if (!require('knitr')) install.packages('knitr'); library('knitr')
knitr::opts_chunk$set(warning=FALSE, message=FALSE, fig.align='center')

###############
# Carbon and Nitrogen Isotopic Analysis of Individual Amino Acids in Montipora capitata
# Author: C. Wall
# Collaborators: Brian Popp, Ruth Gates
# Institution: University of Hawai'i at Mānoa
###############

# Load in packages
if (!require("pacman")) install.packages("pacman"); library(pacman) # for rapid install if not in library

pacman::p_load(devtools, ellipse, ggbiplot, vqv, patchwork, graphics, plyr, effects, MASS, tidyverse, dplyr, plotrix, vegan, cowplot, caret, reshape)

Background

Techniques for Compound Specific Isotope Analysis (CSIA) of individual amino acids (AA) have been developed to better understand ecosystem food webs, trophic positions, and sources of nutrition in biological samples ranging from bacteria to cetaceans. Bulk tissue isotope analysis requires separate accounting for isotopic signatures at the base of the food web, which vary in across locations and time periods. However, CSIA can account for both source and trophic isotope effects in a single sample of a consumer’s tissue.

Source amino acids are a group of AA that exhibit little change in isotopic composition with increasing trophic levels and reflect the isotopic composition of the ‘source material’ at the base of the food web from which they originated.

Trophic amino acids on the other hand are a group of AA that show significant 15N enrichment compared to source-AA, which correspond to trophic steps.This enrichment is quite large and may exceed 8 ‰.

Bulk isotopes

Carbon and nitrogen isotope values in plankton, Symbiodiniaceae symbionts and coral host tissues. With linear models testing effect of treatment and fraction

bulk<-read.csv("data/bulkCN.isotopes.csv")
bulk$Treat.Int<-factor(bulk$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))
bulk$Fraction<-factor(bulk$Fraction, levels=c("host", "symb", "plank"))

bulk.HS<-bulk[!(bulk$Fraction=="plank"),] # plankton removed from fraction

bulk.d15N.means<-aggregate(d15N~Fraction+Treat.Int, data=bulk, mean, na.rm=TRUE); bulk.d15N.means
##   Fraction Treat.Int d15N
## 1     host      L-NF 5.35
## 2     symb      L-NF 4.20
## 3     host       L-F 5.35
## 4     symb       L-F 4.05
## 5     host       D-F 5.45
## 6     symb       D-F 4.40
## 7    plank     plank 7.10
bulk.d13C.means<-aggregate(d13C~Fraction+Treat.Int, data=bulk, mean, na.rm=TRUE); bulk.d13C.means
##   Fraction Treat.Int   d13C
## 1     host      L-NF -16.60
## 2     symb      L-NF -17.40
## 3     host       L-F -16.55
## 4     symb       L-F -17.60
## 5     host       D-F -15.75
## 6     symb       D-F -15.95
## 7    plank     plank -21.80
bulk.CN.means<-aggregate(C.N~Fraction+Treat.Int, data=bulk, mean, na.rm=TRUE); bulk.CN.means
##   Fraction Treat.Int      C.N
## 1     host      L-NF 6.201642
## 2     symb      L-NF 6.711709
## 3     host       L-F 6.259647
## 4     symb       L-F 7.022590
## 5     host       D-F 5.973318
## 6     symb       D-F 5.328831
## 7    plank     plank 4.418660
bulk.means<-cbind(bulk.d15N.means, bulk.d13C.means[3], bulk.CN.means[3])


### fig formatting
format.fig<-
  theme(axis.ticks.length=unit(0.25, "cm"), 
        axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")),
        axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(text = element_text(size=8)) +
  theme(legend.text=element_text(size=10), legend.key = element_blank()) +
  theme(panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank(),
      panel.background = element_blank(), 
      axis.line = element_line(colour = "black",  size=0.5))


##### bulk figures
d13C.m<-aggregate(d13C~Treat.Int, data=bulk, mean, na.rm=TRUE)
d13C.n<-aggregate(d13C~Treat.Int, data=bulk, length)

# d13C
d13C.plot<-ggplot(bulk, aes(y=d13C, x=Treat.Int))+
  geom_boxplot(aes(fill=Fraction)) + 
  geom_dotplot(aes(fill = Fraction, color = Fraction),
               binaxis='y', stackdir='center', dotsize = 0.5, alpha=0.5,
               position = position_dodge(0.75))+
  ylab(expression(paste(delta^{13}, C, " (\u2030, V-PDB)")))+
  xlab("Treatment") + theme(legend.title = element_blank()) +
  format.fig 

anova(lm(d13C ~ Fraction+Treat.Int, data=bulk.HS))
## Analysis of Variance Table
## 
## Response: d13C
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1 1.4008 1.40083  1.5317 0.2510
## Treat.Int  2 3.7717 1.88583  2.0620 0.1896
## Residuals  8 7.3167 0.91458
# d15N
d15N.plot<-ggplot(bulk, aes(y=d15N, x=Treat.Int))+
  geom_boxplot(aes(fill=Fraction)) + 
  geom_dotplot(aes(fill = Fraction, color = Fraction),
               binaxis='y', stackdir='center', dotsize = 0.5, alpha=0.5,
               position = position_dodge(0.75))+
  ylab(expression(paste(delta^{15}, N, " (\u2030, air)")))+
  xlab("Treatment") +
  format.fig + theme(legend.position = "none")

anova(lm(d15N ~ Fraction+Treat.Int, data=bulk.HS))
## Analysis of Variance Table
## 
## Response: d15N
##           Df Sum Sq Mean Sq F value   Pr(>F)   
## Fraction   1 4.0833  4.0833 14.7702 0.004925 **
## Treat.Int  2 0.1050  0.0525  0.1899 0.830662   
## Residuals  8 2.2117  0.2765                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
####
# C:N
C.N.plot<-ggplot(bulk, aes(y=C.N, x=Treat.Int), na.rm=T)+
  geom_boxplot(aes(fill=Fraction)) +
  geom_dotplot(aes(fill = Fraction, color = Fraction),
               binaxis='y', stackdir='center', dotsize = 0.5, alpha=0.5,
               position = position_dodge(0.75))+
  ylab(expression(paste(C:N)))+
  xlab("Treatment") +
  format.fig + theme(legend.position = "none")

anova(lm(C.N ~ Fraction+Treat.Int, data=bulk.HS))
## Analysis of Variance Table
## 
## Response: C.N
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## Fraction   1 0.13168 0.13168  0.7228 0.41995  
## Treat.Int  2 2.21760 1.10880  6.0861 0.02474 *
## Residuals  8 1.45749 0.18219                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
####
# d13H-S
d13C.HS.plot<-ggplot(bulk.HS, aes(y=d13C.H.S, x=Treat.Int), na.rm=T)+
  geom_boxplot() + 
  geom_dotplot(
               binaxis='y', stackdir='center', dotsize = 0.5, alpha=0.5,
               position = position_dodge(0.75))+
  ylab(expression(paste(delta^{13}, C[H-S], " (\u2030)"))) +
  xlab("Treatment") +
  format.fig + theme(legend.position = "none")

anova(lm(d13C.H.S ~ Treat.Int, data=bulk.HS))
## Analysis of Variance Table
## 
## Response: d13C.H.S
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## Treat.Int  2 0.76333 0.38167  7.8966 0.06378 .
## Residuals  3 0.14500 0.04833                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# d15NH-S
d15N.HS.plot<-ggplot(bulk.HS, aes(y=d15N.H.S, x=Treat.Int), na.rm=T)+
  geom_boxplot() +
  geom_dotplot(
               binaxis='y', stackdir='center', dotsize = 0.5, alpha=0.5,
               position = position_dodge(0.75))+
  ylab(expression(paste(delta^{15}, N[H-S], " (\u2030)")))+
  xlab("Treatment") +
  format.fig + theme(legend.position = "none")

anova(lm(d15N.H.S ~ Treat.Int, data=bulk.HS))
## Analysis of Variance Table
## 
## Response: d15N.H.S
##           Df  Sum Sq  Mean Sq F value Pr(>F)
## Treat.Int  2 0.06333 0.031667  0.2879 0.7685
## Residuals  3 0.33000 0.110000
####

bulk.legend <- get_legend(
  # create some space to the left of the legend
  d13C.plot + theme(legend.box.margin = margin(0, 0, 0, 12)))

bulk.figures<-(d13C.plot+theme(legend.position = "none") | d15N.plot | C.N.plot | d13C.HS.plot | d15N.HS.plot |
                 bulk.legend)
print(bulk.figures)
*Figure 1*. Bulk tissue carbon and nitrogen isotope values for corals (host), their endosymbiont Symbiodiniaceae (symbiont), and a pooled plankton sample (plank) at three Light-by-Feeding nutrition treatments. L-NF (Light-Not Fed, autotrophic), L-F (Light-Fed, mixotrophic), Dark-Fed (heterotrophic). Boxplots are n=2, except for plankton (n=1).

Figure 1. Bulk tissue carbon and nitrogen isotope values for corals (host), their endosymbiont Symbiodiniaceae (symbiont), and a pooled plankton sample (plank) at three Light-by-Feeding nutrition treatments. L-NF (Light-Not Fed, autotrophic), L-F (Light-Fed, mixotrophic), Dark-Fed (heterotrophic). Boxplots are n=2, except for plankton (n=1).

ggsave("figures/Fig 1. bulk isotope.pdf", height=3.5, width=12, encod="MacRoman")

CSIA Carbon and Nitrogen

Carbon in amino acids of plankton, Symbiodiniaceae symbionts and coral host tissues.

######## ######## 
## Carbon 
######## ######## 
rm(list=ls())
d13C.dat<-read.csv("data/d13C.CSIA.wide.csv") # wide form carbon data

colnames(d13C.dat)
d13C.dat$Fraction<-factor(d13C.dat$Fraction, levels=c("host", "symb", "plank"))
d13C.dat$Treat.Int<-factor(d13C.dat$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))
d13C.dat<-d13C.dat[ , !(names(d13C.dat) %in% c("Norleucine", "Aminoadipic.Acid", "Methionine"))] #remove Norleucine, Methionine, Aminoadipic Acid


######## ######## 
## Nitrogen 
######## ######## 
d15N.dat<-read.csv("data/d15N.CSIA.wide.csv") # wide form carbon data
d15N.dat<-d15N.dat[ , !(names(d15N.dat) %in% c("Norleucine", "Aminoadipic.Acid", "Methionine"))]
d15N.dat$Fraction<-factor(d15N.dat$Fraction, levels=c("host", "symb", "plank"))

Permanova

## Permanova carbon
d13C.dat.perm<- d13C.dat[!(d13C.dat$Fraction=="plank"),]
df.manova.C<-d13C.dat.perm[, c(11:23)] # remove factor columns
df.manova.C.abs<-abs(df.manova.C) # change all to absolute values 

set.seed(138)
perman.C<-adonis2(df.manova.C.abs~Fraction*Treat.Int, data=d13C.dat.perm, permutations=1000, 
                method="bray", sqrt.dist = TRUE)
perman.C
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 1000
## 
## adonis2(formula = df.manova.C.abs ~ Fraction * Treat.Int, data = d13C.dat.perm, permutations = 1000, method = "bray", sqrt.dist = TRUE)
##                    Df SumOfSqs      R2      F Pr(>F)
## Fraction            1  0.04509 0.13361 1.4072 0.1818
## Treat.Int           2  0.05214 0.15451 0.8136 0.6803
## Fraction:Treat.Int  2  0.04798 0.14218 0.7487 0.7762
## Residual            6  0.19225 0.56970              
## Total              11  0.33746 1.00000
write.csv(perman.C, "output/perman.C.csv")

## Permanova nitrogen
d15N.dat.perm<- d15N.dat[!(d15N.dat$Fraction=="plank"),]
d15N.dat.perm$Threonine<-d15N.dat.perm$Threonine+3 # adding a constant to make positive values
d15N.dat.perm$Phenylalanine<-d15N.dat.perm$Phenylalanine+3 # adding a constant to make positive values

df.manova.N<-d15N.dat.perm[, c(11:23)] # remove factor columns

set.seed(138)
perman.N<-adonis2(df.manova.N~Fraction*Treat.Int, data=d15N.dat.perm, permutations=1000, 
                method="bray", sqrt.dist = TRUE)
perman.N
## Permutation test for adonis under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 1000
## 
## adonis2(formula = df.manova.N ~ Fraction * Treat.Int, data = d15N.dat.perm, permutations = 1000, method = "bray", sqrt.dist = TRUE)
##                    Df SumOfSqs      R2      F  Pr(>F)  
## Fraction            1  0.17919 0.18890 2.1474 0.01598 *
## Treat.Int           2  0.12370 0.13041 0.7412 0.84815  
## Fraction:Treat.Int  2  0.14502 0.15288 0.8690 0.65634  
## Residual            6  0.50066 0.52781                 
## Total              11  0.94857 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
write.csv(perman.N, "output/perman.N.csv")

PCA

Carbon by treatment

######## ######## ######## ######## 
######## ######## ######## ######## by treatment
# PCA dataframe
PCA.df.C<-d13C.dat[, c(7:8,11:23)]

PC.C<- prcomp(PCA.df.C[,c(-1:-2)], center = TRUE, scale= TRUE) 
PC.C.summary<-summary(PC.C)
ev.C<-PC.C$sdev^2 
newdat.C<-PC.C$x[,1:4] # 2 PCAs explain 81% of variance
#plot(PC, type="lines", main="PC.area eigenvalues")

## PC1 and PC2
trt.color<-c("lightskyblue", "darkgoldenrod1", "gray70", "mediumorchid")

PC.fig1.C.trt <- ggbiplot(PC.C, choices = 1:2, obs.scale = 1, var.scale = 1, 
                             groups= PCA.df.C[,1], ellipse = TRUE,
                             circle = FALSE) +
  scale_color_manual(values=trt.color)+
  theme_classic() +
  scale_x_continuous(breaks=pretty_breaks(n=5))+
  coord_cartesian(xlim = c(-8, 8), ylim=c(-4, 4))+ 
  theme(axis.ticks.length=unit(-0.25, "cm"), axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")), axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(legend.text=element_text(size=15)) +
  theme(panel.background = element_rect(colour = "black", size=1))+
  theme(legend.key = element_blank())+
  theme(legend.direction = 'horizontal', legend.position = 'top') +theme(aspect.ratio=0.8) +
  annotate("text", x=6, y=3.6,  size=5, label= expression(paste(delta^{13},C[AA])))
print(PC.fig1.C.trt)

#ggsave("figures/carbon/PCA_d13C.trt.pdf", height=5, width=8, encod="MacRoman")

Nitrogen by treatment

# PCA dataframe
PCA.df.N<-d15N.dat[, c(7:8,11:23)]
PC.N<- prcomp(PCA.df.N[, c(-1:-2)], center = TRUE, scale= TRUE) 
PC.N.summary<-summary(PC.N)
ev.N<-PC.N$sdev^2 
newdat.N<-PC.N$x[,1:4] # 2 PCAs explain 74% of variance
#plot(PC, type="lines", main="PC.area eigenvalues")

######################## treatments
## PC1 and PC2
PC.fig2.N.trt <- ggbiplot(PC.N, choices = 1:2, obs.scale = 1, var.scale = 1, 
                   groups= PCA.df.N[,1], ellipse = TRUE,
                   circle = FALSE) +
  scale_color_manual(values=trt.color)+
  theme_classic() +
  coord_cartesian(xlim = c(-8, 5), ylim=c(-6, 6)) +
  theme(axis.ticks.length=unit(-0.25, "cm"), axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")), axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(legend.text=element_text(size=15)) +
  theme(panel.background = element_rect(colour = "black", size=1))+
  theme(legend.key = element_blank())+
  theme(legend.direction = 'horizontal', legend.position = 'top') +theme(aspect.ratio=0.8) +
  annotate("text", x=4, y=5.5,  size=5, label= expression(paste(delta^{15},N[AA])))
print(PC.fig2.N.trt)

#ggsave("figures/nitrogen/PCA_d15N.trt.pdf", height=5, width=6, encod="MacRoman")

Carbon PCA by fraction (plankton, host, symbiont)

######## ######## ######## ######## 
######## ######## ######## ######## by fraction
frac.color<- c("coral", "seagreen3", "mediumorchid")
  
PC.fig3.C.frac <- ggbiplot(PC.C, choices = 1:2, obs.scale = 1, var.scale = 1, 
                   groups= PCA.df.C[,2], ellipse = TRUE,
                   circle = FALSE) +
  scale_color_manual(values=frac.color)+
  theme_classic() +
  coord_cartesian(xlim = c(-8, 8), ylim=c(-4, 4)) +
  theme(axis.ticks.length=unit(-0.25, "cm"), axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")), axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(legend.text=element_text(size=15)) +
  theme(panel.background = element_rect(colour = "black", size=1))+
  theme(legend.key = element_blank())+
  theme(legend.direction = 'horizontal', legend.position = 'top') +theme(aspect.ratio=0.8) +
  annotate("text", x=6, y=3.6,  size=5, label= expression(paste(delta^{13},C[AA])))
print(PC.fig3.C.frac)

#ggsave("figures/carbon/PCA_d13C.frac.pdf", height=5, width=8, encod="MacRoman")

Nitrogen PCA by fraction (plankton, host, symbiont)

######################### fractions
## PC1 and PC2
PC.fig4.N.frac <- ggbiplot(PC.N, choices = 1:2, obs.scale = 1, var.scale = 1, 
                   groups= PCA.df.N[,2], ellipse = TRUE,
                   circle = FALSE) +
  scale_color_manual(values=frac.color)+
  theme_classic() +
  coord_cartesian(xlim = c(-8, 5), ylim=c(-6, 6)) + 
  theme(axis.ticks.length=unit(-0.25, "cm"), axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")), axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(legend.text=element_text(size=15)) +
  theme(panel.background = element_rect(colour = "black", size=1))+
  theme(legend.key = element_blank())+
  theme(legend.direction = 'horizontal', legend.position = 'top') +theme(aspect.ratio=0.8) +
  annotate("text", x=4, y=5.5,  size=5, label= expression(paste(delta^{15},N[AA])))
print(PC.fig4.N.frac)

#ggsave("figures/nitrogen/PCA_d15N.frac.pdf", height=5, width=8, encod="MacRoman")

LDA all AA

Break up C and N AA and do LDA for each. Includes all AA in the categories (Non-EAA/EAA) and (Trophic/Source).

# LDA dataframe
LDA.d13C<-d13C.dat[, c(8,11:23)] # (Just 'Fraction' tested here)
LDA.df.N<-d15N.dat[, c(7:8,11:23)]

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.C.samples <- LDA.d13C$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.C.data <- LDA.d13C[training.C.samples, ]
test.C.data <- LDA.d13C[-training.C.samples, ]

#Normalize
# Estimate preprocessing parameters
preproc.param <- train.C.data %>% 
  preProcess(method = c("center", "scale"))

# Transform the data using the estimated parameters
train.transformed <- preproc.param %>% predict(train.C.data)
test.transformed <- preproc.param %>% predict(test.C.data)

# Fit the model (Just Fraction tested here)
model.C.frac <- lda(Fraction~., data = train.transformed)

# Make predictions
predictions <- model.C.frac %>% predict(test.transformed)

# Model accuracy
mean(predictions$class==test.transformed$Fraction) #0.5 accuracy
## [1] 0
### INFO ###
# LDA determines group means and computes, for each individual, the probability of belonging to the different groups. The individual is then affected to the group with the highest probability score.

# Output:
#Prior probabilities of groups: the proportion of training observations in each group. For example, there are 31% of the training observations in the setosa group
# Group means: group center of gravity. Shows the mean of each variable in each group.
# Coefficients of linear discriminants: Shows the linear combination of predictor variables that are used to form the LDA decision rule.

# Make predictions
predictions <- model.C.frac %>% predict(test.transformed)
names(predictions)
## [1] "class"     "posterior" "x"
#The predict() function returns the following elements:

#class: predicted classes of observations.
#posterior: is a matrix whose columns are the groups, rows are the individuals and values are the posterior probability that the corresponding observation belongs to the groups.
#x: contains the linear discriminants, described above


# Predicted classes
head(predictions$class, 6)
## [1] plank host 
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions$posterior, 6) 
##           host         symb        plank
## 1 6.409439e-29 1.463557e-05 9.999854e-01
## 3 9.997676e-01 2.323526e-04 1.606492e-38
# Linear discriminants
head(predictions$x, 3)
##          LD1       LD2
## 1  9.4802049 -4.229743
## 3 -0.8072902  1.182156
LDA.C.data <- cbind(train.transformed, predict(model.C.frac)$x)

mean(predictions$class==test.transformed$Fraction)
## [1] 0
# LDA d13C-AA Fraction

# for ellipses
library(ellipse)
dat_ell <- data.frame()
for(g in levels(LDA.C.data$Fraction)){
dat_ell <- rbind(dat_ell, cbind(as.data.frame(with(LDA.C.data[LDA.C.data$Fraction==g,], ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.C.frac<-ggplot(LDA.C.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  geom_path(data=dat_ell, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
  scale_color_manual(values=frac.color)+
  coord_cartesian(xlim = c(-4, 14), ylim=c(-4, 4)) + 
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.C.frac)

########### LDA Nitrogen

# LDA dataframe
LDA.df.N<-d15N.dat[, c(8,11:23)] # (Just 'Fraction' tested here)

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.N.samples <- LDA.df.N$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.N.data <- LDA.df.N[training.N.samples, ]
test.N.data <- LDA.df.N[-training.N.samples, ]

preproc.N.param <- train.N.data %>% 
  preProcess(method = c("center", "scale"))

train.N.transformed <- preproc.N.param %>% predict(train.N.data)
test.N.transformed <- preproc.N.param %>% predict(test.N.data)

# Fit the model (Just Fraction tested here)
model.N.frac <- lda(Fraction~., data = train.N.transformed)

# Make predictions
predictions.N <- model.N.frac %>% predict(test.N.transformed)

# Model accuracy
mean(predictions.N$class==test.N.transformed$Fraction) #0.5 accuracy
## [1] 0.5
# Make predictions
predictions.N <- model.N.frac %>% predict(test.N.transformed)
names(predictions.N)
## [1] "class"     "posterior" "x"
# Predicted classes
head(predictions.N$class, 6)
## [1] symb symb
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions.N$posterior, 6) 
##         host      symb        plank
## 2 0.03037680 0.9696232 4.299412e-34
## 3 0.01346862 0.9865314 1.659611e-29
# Linear discriminants
head(predictions.N$x, 3)
##           LD1       LD2
## 2 -0.70623181 -1.303294
## 3  0.02194191 -2.174022
LDA.N.data <- cbind(train.N.transformed, predict(model.N.frac)$x)

mean(predictions.N$class==test.N.transformed$Fraction)
## [1] 0.5
# LDA d13C-AA Fraction

# for ellipses
dat_ell.N <- data.frame()
for(g in levels(LDA.N.data$Fraction)){
dat_ell.N <- rbind(dat_ell.N, cbind(as.data.frame(with(LDA.N.data[LDA.N.data$Fraction==g,], 
                                                       ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.N.frac<-ggplot(LDA.N.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  scale_color_manual(values=frac.color) +
  geom_path(data=dat_ell.N, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
  coord_cartesian(xlim = c(-4, 14), ylim=c(-4, 4)) + 
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.N.frac)

plot_grid(LDA.C.frac, LDA.N.frac)

LDA Carbon Non-EAA/EAA

# LDA dataframe
# looking at Non-essential AA and Essential 
# Non-EAA = Ala, Asp, Gly, Glu, Pro, Ser, Tyr
# EAA = Ile, Leu, Lys, Phe, Thr, Val


########################## 
########################## Non-EAA C

# looking Non-EAA
# Non-EAA = Ala, Asp, Gly, Glu, Pro, Ser, Tyr
                               
LDA.df.NEAAC<-LDA.d13C %>% 
  select(Fraction, Alanine, Aspartic.acid, Glycine, Glutamic.acid, Proline, Serine, Tyrosine) 
# (Just 'Trophc' fractions here)

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.C.NEAA.samples <- LDA.df.NEAAC$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.C.NEAA.data <- LDA.df.NEAAC[training.C.NEAA.samples, ]
test.C.NEAA.data <- LDA.df.NEAAC[-training.C.NEAA.samples, ]

preproc.C.NEAA.param <- train.C.NEAA.data %>% 
  preProcess(method = c("center", "scale"))

train.C.NEAA.transformed <- preproc.C.NEAA.param %>% predict(train.C.NEAA.data)
test.C.NEAA.transformed <- preproc.C.NEAA.param %>% predict(test.C.NEAA.data)

# Fit the model (Just Fraction tested here)
model.C.NEAA <- lda(Fraction~., data = train.C.NEAA.transformed)

# Make predictions
predictions.C.NEAA <- model.C.NEAA %>% predict(test.C.NEAA.transformed)

# Model accuracy
mean(predictions.C.NEAA$class==test.C.NEAA.transformed$Fraction) #0.5 accuracy
## [1] 0.5
# Make predictions
predictions.C.NEAA <- model.C.NEAA %>% predict(test.C.NEAA.transformed)
names(predictions.C.NEAA)
## [1] "class"     "posterior" "x"
# Predicted classes
head(predictions.C.NEAA$class, 6)
## [1] host  plank
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions.C.NEAA$posterior, 6) 
##        host        symb         plank
## 1 1.0000000 0.00000e+00 2.125322e-205
## 3 0.4933633 5.17668e-21  5.066367e-01
# Linear discriminants
head(predictions.C.NEAA$x, 3)
##          LD1       LD2
## 1 -38.259833 -8.713046
## 3  -2.273748  1.191146
LDA.C.NEAA.data <- cbind(train.C.NEAA.transformed, predict(model.C.NEAA)$x)

mean(predictions.C.NEAA$class==test.C.NEAA.transformed$Fraction)
## [1] 0.5
# LDA d13C-AA Fraction

# for ellipses
dat_ell.C.NEAA <- data.frame()
for(g in levels(LDA.C.data$Fraction)){
dat_ell.C.NEAA <- rbind(dat_ell.C.NEAA, cbind(as.data.frame(with(LDA.C.NEAA.data[LDA.C.NEAA.data$Fraction==g,],
                                        ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.C.NEAA<-ggplot(LDA.C.NEAA.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  scale_color_manual(values=frac.color)+
  ggtitle(expression(paste(Non-EAA,~delta^{13}, C[AA], ""))) +
  coord_cartesian(xlim = c(-10, 15), ylim=c(-5, 5)) + 
  geom_path(data=dat_ell.C.NEAA, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.C.NEAA)

########## ########## ########## 
########## EAA 

LDA.df.EAAC<-LDA.d13C %>% 
  select(Fraction, Isoleucine, Leucine, Lysine, Phenylalanine, Threonine, Valine) 
# (Just 'Trophc' fractions here)

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.C.EAA.samples <- LDA.df.EAAC$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.C.EAA.data <- LDA.df.EAAC[training.C.EAA.samples, ]
test.C.EAA.data <- LDA.df.EAAC[-training.C.EAA.samples, ]

preproc.C.EAA.param <- train.C.EAA.data %>% 
  preProcess(method = c("center", "scale"))

train.C.EAA.transformed <- preproc.C.EAA.param %>% predict(train.C.EAA.data)
test.C.EAA.transformed <- preproc.C.EAA.param %>% predict(test.C.EAA.data)

# Fit the model (Just Fraction tested here)
model.C.EAA <- lda(Fraction~., data = train.C.EAA.transformed)

# Make predictions
predictions.C.EAA <- model.C.EAA %>% predict(test.C.EAA.transformed)

# Model accuracy
mean(predictions.C.EAA$class==test.C.EAA.transformed$Fraction) #0.5 accuracy
## [1] 0.5
# Make predictions
predictions.C.EAA <- model.C.EAA %>% predict(test.C.EAA.transformed)
names(predictions.C.EAA)
## [1] "class"     "posterior" "x"
# Predicted classes
head(predictions.C.EAA$class, 6)
## [1] host  plank
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions.C.EAA$posterior, 6) 
##           host         symb        plank
## 1 1.000000e+00 7.460999e-37 1.177377e-37
## 3 7.099417e-05 5.910248e-44 9.999290e-01
# Linear discriminants
head(predictions.C.EAA$x, 3)
##        LD1      LD2
## 1 11.49592 8.217632
## 3 14.52308 2.883417
LDA.C.EAA.data <- cbind(train.C.EAA.transformed, predict(model.C.EAA)$x)

mean(predictions.C.EAA$class==test.C.EAA.transformed$Fraction)
## [1] 0.5
# LDA d13C-AA Fraction

# for ellipses
dat_ell.C.EAA <- data.frame()
for(g in levels(LDA.C.data$Fraction)){
dat_ell.C.EAA <- rbind(dat_ell.C.EAA, cbind(as.data.frame(with(LDA.C.EAA.data[LDA.C.EAA.data$Fraction==g,], 
                                                       ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.C.EAA<-ggplot(LDA.C.EAA.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  scale_color_manual(values=frac.color)+
  ggtitle(expression(paste(EAA,~delta^{13}, C[AA], ""))) +
  coord_cartesian(xlim = c(-10, 15), ylim=c(-5, 5)) + 
  geom_path(data=dat_ell.C.EAA, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.C.EAA)

plot_grid(LDA.C.NEAA, LDA.C.EAA)

LDA Nitrogen Trophic/Source

# LDA dataframe
# looking at  Trophic and Source
# Trophic = Ala, Asp, Glu, Ile, Leu, Val, Pro
# Source = Gly, Set, Ser, Phe, Thr, Tyr


########## Trophic AA

LDA.df.TrN<-LDA.df.N %>% 
  select(Fraction, Alanine, Aspartic.acid, Glutamic.acid, Isoleucine, Leucine, Valine, Proline) 
# (Just 'Trophc' fractions here)

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.N.Tr.samples <- LDA.df.TrN$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.N.Tr.data <- LDA.df.TrN[training.N.Tr.samples, ]
test.N.Tr.data <- LDA.df.TrN[-training.N.Tr.samples, ]

preproc.N.Tr.param <- train.N.Tr.data %>% 
  preProcess(method = c("center", "scale"))

train.N.Tr.transformed <- preproc.N.Tr.param %>% predict(train.N.Tr.data)
test.N.Tr.transformed <- preproc.N.Tr.param %>% predict(test.N.Tr.data)

# Fit the model (Just Fraction tested here)
model.N.Tr <- lda(Fraction~., data = train.N.Tr.transformed)

# Make predictions
predictions.N.Tr <- model.N.Tr %>% predict(test.N.Tr.transformed)

# Model accuracy
mean(predictions.N.Tr$class==test.N.Tr.transformed$Fraction) #0.5 accuracy
## [1] 0
# Make predictions
predictions.N.Tr <- model.N.Tr %>% predict(test.N.Tr.transformed)
names(predictions.N.Tr)
## [1] "class"     "posterior" "x"
# Predicted classes
head(predictions.N.Tr$class, 6)
## [1] symb host
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions.N.Tr$posterior, 6) 
##           host       symb         plank
## 2 1.049318e-08 0.99999999 1.761058e-105
## 3 9.722014e-01 0.02779858  1.375852e-88
# Linear discriminants
head(predictions.N.Tr$x, 3)
##         LD1       LD2
## 2 -4.065532 -1.082257
## 3 -2.028678  1.279761
LDA.N.Tr.data <- cbind(train.N.Tr.transformed, predict(model.N.Tr)$x)

mean(predictions.N.Tr$class==test.N.Tr.transformed$Fraction)
## [1] 0
# LDA d13C-AA Fraction

# for ellipses
dat_ell.N.Tr <- data.frame()
for(g in levels(LDA.N.data$Fraction)){
dat_ell.N.Tr <- rbind(dat_ell.N.Tr, cbind(as.data.frame(with(LDA.N.Tr.data[LDA.N.Tr.data$Fraction==g,], 
                                                       ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.N.Tr<-ggplot(LDA.N.Tr.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  scale_color_manual(values=frac.color) +
  ggtitle(expression(paste(Trophic,~delta^{15}, N[AA], ""))) +
  coord_cartesian(xlim = c(-10, 20), ylim=c(-6, 6)) + 
  geom_path(data=dat_ell.N.Tr, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.N.Tr)

#################
########################## Source AA N

# looking Source
# Source = Gly, Set, Ser, Phe, Thr, Tyr
                               
LDA.df.SrN<-LDA.df.N %>% 
  select(Fraction, Glycine, Serine, Phenylalanine, Threonine, Tyrosine) 
# (Just 'Trophc' fractions here)

# Split the data into training (80%) and test set (20%)
set.seed(123)
training.N.Sr.samples <- LDA.df.SrN$Fraction %>%
  createDataPartition(p = 0.8, list = FALSE)
train.N.Sr.data <- LDA.df.SrN[training.N.Sr.samples, ]
test.N.Sr.data <- LDA.df.SrN[-training.N.Sr.samples, ]

preproc.N.Sr.param <- train.N.Sr.data %>% 
  preProcess(method = c("center", "scale"))

train.N.Sr.transformed <- preproc.N.Sr.param %>% predict(train.N.Sr.data)
test.N.Sr.transformed <- preproc.N.Sr.param %>% predict(test.N.Sr.data)

# Fit the model (Just Fraction tested here)
model.N.Sr <- lda(Fraction~., data = train.N.Sr.transformed)

# Make predictions
predictions.N.Sr <- model.N.Sr %>% predict(test.N.Sr.transformed)

# Model accuracy
mean(predictions.N.Sr$class==test.N.Sr.transformed$Fraction) #0.5 accuracy
## [1] 1
# Make predictions
predictions.N.Sr <- model.N.Sr %>% predict(test.N.Sr.transformed)
names(predictions.N.Sr)
## [1] "class"     "posterior" "x"
# Predicted classes
head(predictions.N.Sr$class, 6)
## [1] host symb
## Levels: host symb plank
# Predicted probabilities of class membership.
head(predictions.N.Sr$posterior, 6) 
##         host        symb        plank
## 2 0.99694628 0.003053716 2.670533e-22
## 3 0.03919395 0.960806047 1.787077e-45
# Linear discriminants
head(predictions.N.Sr$x, 3)
##         LD1        LD2
## 2  1.577231 -0.1241904
## 3 -2.660558  0.2897541
LDA.N.Sr.data <- cbind(train.N.Sr.transformed, predict(model.N.Sr)$x)

mean(predictions.N.Sr$class==test.N.Sr.transformed$Fraction)
## [1] 1
# LDA d13C-AA Fraction

# for ellipses
dat_ell.N.Sr <- data.frame()
for(g in levels(LDA.N.data$Fraction)){
dat_ell.N.Sr <- rbind(dat_ell.N.Sr, cbind(as.data.frame(with(LDA.N.Sr.data[LDA.N.Sr.data$Fraction==g,], 
                                                       ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))),Fraction=g))
}

LDA.N.Sr<-ggplot(LDA.N.Sr.data, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction))+
  scale_color_manual(values=frac.color)+
  ggtitle(expression(paste(Source,~delta^{15}, N[AA], ""))) +
  coord_cartesian(xlim = c(-10, 20), ylim=c(-6, 6)) + 
  geom_path(data=dat_ell.N.Sr, aes(x=x,y=y,color=Fraction),size=0.5,linetype=2)  +
   theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        panel.background=element_blank())

print(LDA.N.Sr)

plot_grid(LDA.N.Tr, LDA.N.Sr)

Carbon AA

Models

Run models looking for effects of Fraction or the Treatment-Interaction (feeding/light).

d13C.dat2<-d13C.dat[!(d13C.dat$Fraction=="plank"),] #remove plankton for now
d13C.host<-d13C.dat[(d13C.dat$Fraction=="host"),] # just host
d13C.symb<-d13C.dat[(d13C.dat$Fraction=="symb"),] # just symbiont

for(i in c(11:23)){
  Y=d13C.dat2[,i]
  mod<-aov(Y~Fraction+Treat.Int, data=d13C.dat2)
  print(anova(mod))
  print(TukeyHSD(mod))
  plot(allEffects(mod), ylab=colnames(d13C.dat2)[i], cex.axis=0.5, cex.lab=0.5)
}
## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## Fraction   1  7.9280  7.9280  4.8489 0.05881 .
## Treat.Int  2  2.3861  1.1931  0.7297 0.51157  
## Residuals  8 13.0802  1.6350                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr        upr     p adj
## symb-host -1.625629 -3.328026 0.07676902 0.0588088
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -1.0214364 -3.605031 1.562158 0.5238902
## D-F-L-NF -0.1756140 -2.759208 2.407980 0.9794709
## D-F-L-F   0.8458224 -1.737772 3.429417 0.6346704

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value   Pr(>F)   
## Fraction   1 43.514  43.514  16.281 0.003762 **
## Treat.Int  2 38.910  19.455   7.279 0.015818 * 
## Residuals  8 21.382   2.673                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr       upr     p adj
## symb-host -3.808515 -5.985115 -1.631916 0.0037621
## 
## $Treat.Int
##               diff       lwr       upr     p adj
## L-F-L-NF -2.323060 -5.626314 0.9801931 0.1719320
## D-F-L-NF  2.085575 -1.217679 5.3888282 0.2286943
## D-F-L-F   4.408635  1.105382 7.7118885 0.0126616

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  2.197  2.1971  0.4464 0.5228
## Treat.Int  2  5.526  2.7628  0.5614 0.5914
## Residuals  8 39.372  4.9215               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr     upr     p adj
## symb-host 0.8557828 -2.097784 3.80935 0.5228408
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -1.6618056 -6.144201 2.820590 0.5632924
## D-F-L-NF -0.8014268 -5.283822 3.680969 0.8682426
## D-F-L-F   0.8603788 -3.622017 5.342774 0.8501124

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.5098  0.5098  0.1910 0.6736
## Treat.Int  2 13.3334  6.6667  2.4977 0.1436
## Residuals  8 21.3529  2.6691               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr     upr     p adj
## symb-host 0.4122222 -1.762895 2.58734 0.6736481
## 
## $Treat.Int
##               diff        lwr      upr     p adj
## L-F-L-NF -1.363812 -4.6648158 1.937192 0.4961333
## D-F-L-NF  1.216790 -2.0842139 4.517794 0.5667464
## D-F-L-F   2.580602 -0.7204022 5.881606 0.1247308

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  3.0549  3.0549  1.2730 0.2919
## Treat.Int  2  4.4772  2.2386  0.9328 0.4324
## Residuals  8 19.1986  2.3998               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr      upr    p adj
## symb-host -1.009111 -3.071587 1.053365 0.291906
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -0.5855417 -3.715598 2.544515 0.8569269
## D-F-L-NF  0.8996250 -2.230431 4.029681 0.7011505
## D-F-L-F   1.4851667 -1.644890 4.615223 0.4064527

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1 0.1806 0.18060  0.1457 0.7126
## Treat.Int  2 1.8191 0.90953  0.7340 0.5097
## Residuals  8 9.9129 1.23912               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                 diff       lwr      upr     p adj
## symb-host -0.2453535 -1.727379 1.236672 0.7125759
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -0.5112879 -2.760441 1.737865 0.7978109
## D-F-L-NF  0.4415530 -1.807600 2.690706 0.8439105
## D-F-L-F   0.9528409 -1.296312 3.201994 0.4800982

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  2.301  2.3006  0.5090 0.4958
## Treat.Int  2  0.536  0.2681  0.0593 0.9428
## Residuals  8 36.157  4.5196               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                 diff       lwr      upr     p adj
## symb-host -0.8757071 -3.706106 1.954692 0.4958429
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -0.1529924 -4.448466 4.142481 0.9943098
## D-F-L-NF  0.3519318 -3.943541 4.647405 0.9703487
## D-F-L-F   0.5049242 -3.790549 4.800398 0.9401608

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## Fraction   1 10.0959 10.0959  5.0226 0.05533 .
## Treat.Int  2  1.9626  0.9813  0.4882 0.63089  
## Residuals  8 16.0806  2.0101                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr        upr     p adj
## symb-host -1.834472 -3.722052 0.05310792 0.0553284
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -0.9262500 -3.790881 1.938381 0.6413964
## D-F-L-NF -0.1589583 -3.023590 2.705673 0.9862591
## D-F-L-F   0.7672917 -2.097340 3.631923 0.7333288

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  1.9366 1.93656  0.8704 0.3781
## Treat.Int  2  1.1095 0.55476  0.2494 0.7851
## Residuals  8 17.7984 2.22480               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr      upr     p adj
## symb-host 0.8034428 -1.182399 2.789285 0.3781308
## 
## $Treat.Int
##                diff       lwr      upr     p adj
## L-F-L-NF -0.3559343 -3.369690 2.657821 0.9396161
## D-F-L-NF -0.7445833 -3.758339 2.269172 0.7668729
## D-F-L-F  -0.3886490 -3.402404 2.625106 0.9285371

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value   Pr(>F)   
## Fraction   1 15.4184 15.4184 15.5000 0.004314 **
## Treat.Int  2  7.1774  3.5887  3.6077 0.076423 . 
## Residuals  8  7.9579  0.9947                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr        upr     p adj
## symb-host -2.267039 -3.594905 -0.9391742 0.0043141
## 
## $Treat.Int
##                diff        lwr      upr     p adj
## L-F-L-NF -0.3928728 -2.4080690 1.622323 0.8458544
## D-F-L-NF  1.4084868 -0.6067093 3.423683 0.1749601
## D-F-L-F   1.8013597 -0.2138365 3.816556 0.0781114

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.4717 0.47171  0.3402 0.5758
## Treat.Int  2  1.7167 0.85836  0.6190 0.5624
## Residuals  8 11.0933 1.38666               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                 diff       lwr      upr     p adj
## symb-host -0.3965321 -1.964311 1.171246 0.5757947
## 
## $Treat.Int
##                  diff       lwr      upr     p adj
## L-F-L-NF  0.805110680 -1.574183 3.184404 0.6164040
## D-F-L-NF  0.799570313 -1.579723 3.178864 0.6202649
## D-F-L-F  -0.005540367 -2.384834 2.373753 0.9999756

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.4274 0.42736  0.2195 0.6519
## Treat.Int  2  3.7940 1.89702  0.9743 0.4181
## Residuals  8 15.5772 1.94716               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                diff       lwr      upr     p adj
## symb-host 0.3774306 -1.480373 2.235234 0.6519364
## 
## $Treat.Int
##               diff       lwr      upr     p adj
## L-F-L-NF 1.1068359 -1.712606 3.926277 0.5282887
## D-F-L-NF 1.2633138 -1.556128 4.082755 0.4438334
## D-F-L-F  0.1564779 -2.662964 2.975919 0.9862544

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.7150 0.71500  0.4577 0.5178
## Treat.Int  2  0.0828 0.04142  0.0265 0.9739
## Residuals  8 12.4980 1.56225               
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Y ~ Fraction + Treat.Int, data = d13C.dat2)
## 
## $Fraction
##                 diff       lwr      upr     p adj
## symb-host -0.4881944 -2.152277 1.175888 0.5177911
## 
## $Treat.Int
##                 diff       lwr      upr     p adj
## L-F-L-NF  0.14959239 -2.375854 2.675039 0.9843613
## D-F-L-NF -0.04470109 -2.570148 2.480746 0.9985909
## D-F-L-F  -0.19429348 -2.719740 2.331153 0.9737967

# Almost Fraction effect for Alanine, Proline
# Fraction effect for: Glycine, Glutamic acid
# Treatment effect for: Glycine
# Almost Treatment effect: Glutamic Acid

############ just host
for(i in c(11:23)){
  Y=d13C.host[,i]
  mod<-aov(Y~Treat.Int, data=d13C.host)
  print(anova(mod))
  #print(TukeyHSD(mod))
  plot(allEffects(mod), ylab=colnames(d13C.host)[i], cex.axis=0.5, cex.lab=0.5)
}
## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 0.0932 0.04660  0.0567 0.9459
## Residuals  3 2.4654 0.82179

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value  Pr(>F)  
## Treat.Int  2 10.8858  5.4429  7.9309 0.06343 .
## Residuals  3  2.0589  0.6863                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2  6.8484  3.4242  0.4379  0.681
## Residuals  3 23.4580  7.8193

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 6.8177  3.4088  1.3167 0.3886
## Residuals  3 7.7669  2.5890

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 0.9241 0.46205  0.1674 0.8533
## Residuals  3 8.2826 2.76086

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 1.5210 0.76052  0.5506 0.6256
## Residuals  3 4.1441 1.38137

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2  0.2875  0.1438  0.0418 0.9596
## Residuals  3 10.3123  3.4374

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 1.21445 0.60723   2.347 0.2435
## Residuals  3 0.77618 0.25873

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 2.1362 1.06810    1.37 0.3778
## Residuals  3 2.3388 0.77962

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 4.3768  2.1884  1.5503 0.3448
## Residuals  3 4.2349  1.4116

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 2.9503  1.4751  0.9893 0.4677
## Residuals  3 4.4731  1.4910

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 5.4088  2.7044  1.4422  0.364
## Residuals  3 5.6255  1.8752

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 2.3085 1.15427  3.3645 0.1712
## Residuals  3 1.0292 0.34307

# If running only "Treat.Int" no effects accept p=0.06 for glycine
# If running "Light.Trt+Feed.Trt" then p=0.03 for glycine

############ just symbiont
for(i in c(11:23)){
  Y=d13C.symb[,i]
  mod<-aov(Y~Treat.Int, data=d13C.symb)
  print(anova(mod))
  #print(TukeyHSD(mod))
  plot(allEffects(mod), ylab=colnames(d13C.symb)[i], cex.axis=0.5, cex.lab=0.5)
}
## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 3.7832  1.8916  0.6219 0.5943
## Residuals  3 9.1245  3.0415

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 30.814 15.4072  2.7958 0.2063
## Residuals  3 16.533  5.5109

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2  2.3166  1.1583  0.2831 0.7716
## Residuals  3 12.2743  4.0914

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## Treat.Int  2 17.036  8.5178  8.3344 0.05957 .
## Residuals  3  3.066  1.0220                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 4.4949  2.2475   0.676 0.5723
## Residuals  3 9.9741  3.3247

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 0.4550  0.2275  0.1216 0.8896
## Residuals  3 5.6118  1.8706

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2  0.8795  0.4397  0.0523 0.9499
## Residuals  3 25.2135  8.4045

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2  1.2539  0.6270  0.1271 0.8851
## Residuals  3 14.7986  4.9329

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 7.4714  3.7357  1.6099  0.335
## Residuals  3 6.9615  2.3205

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 2.9467  1.4733  1.2357  0.406
## Residuals  3 3.5769  1.1923

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 0.0713 0.03566  0.0201 0.9802
## Residuals  3 5.3153 1.77176

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 4.3532  2.1766  1.6391 0.3303
## Residuals  3 3.9837  1.3279

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Treat.Int  2 1.8423 0.92114  0.3734 0.7165
## Residuals  3 7.4008 2.46694

# If running only "Treat.Int" no effects
# If running "Light.Trt+Feed.Trt" then p=0.03 for serine

Figures

-New dataframe (long format) here to make figures. Same data as above.

###########
###########
# CSAA.dat long

d13C.dat.long<-read.csv("data/d13C.CSIA.long.csv")
#str(d13C.dat.long)

d13C.dat.long<-d13C.dat.long[!(d13C.dat.long$Amino.acid=="Methionine"),]
d13C.dat.long<-d13C.dat.long[!(d13C.dat.long$Amino.acid=="Norleucine"),]
d13C.dat.long<-d13C.dat.long[!(d13C.dat.long$Amino.acid=="Aminoadipic Acid"),] # remove unwanted data

d13C.dat.long$AA.short<-mapvalues(d13C.dat.long$Amino.acid, from =c("Alanine", "Aspartic acid", "Glutamic acid", "Glycine", "Isoleucine", "Leucine", "Lysine", "Phenylalanine", "Proline", "Serine", "Threonine", "Tyrosine", "Valine"), to = c("Ala", "Asp", "Glu", "Gly", "Ile", "Leu", "Lys", "Phe", "Pro", "Ser", "Thr", "Tyr", "Val"))

d13C.dat.long$AA.short<-factor(d13C.dat.long$AA.short, levels=c("Ala","Asp", "Gly", "Glu", "Pro", "Ser", "Tyr", "Ile", "Leu", "Lys", "Phe", "Thr", "Val"))

d13C.dat.long$Treat.Int<-factor(d13C.dat.long$Treat.Int, levels=c("L-NF", "L-F", "D-F", "Plank"))


# looking at average essential and non-essential AA
d13C.dat.long$AA.cat<-ifelse(d13C.dat.long$AA.short=="Ala" |d13C.dat.long$AA.short=="Asp" |
                               d13C.dat.long$AA.short=="Gly" | d13C.dat.long$AA.short=="Glu" |
                               d13C.dat.long$AA.short=="Pro" | d13C.dat.long$AA.short=="Ser" | 
                               d13C.dat.long$AA.short=="Tyr", "Non-EAA", "EAA")

dfC<-d13C.dat.long

Table: Carbon Essential and Non-essential AA

##################
# all essentail and non-essential AA
AA.means<-aggregate(d13C.value~AA.cat+Treat.Int+Fraction, data=dfC, mean, na.rm=TRUE); AA.means
AA.sd<-aggregate(d13C.value~AA.cat+Treat.Int+Fraction, data=dfC, sd, na.rm=TRUE)
colnames(AA.sd)[4]="SD"
AA.means<-cbind(AA.means, AA.sd[4])
AA.means$Fraction<-factor(AA.means$Fraction, levels=c("host", "symb", "plank"))
  • d13C by fraction and treatments, showing d13C.CSIA_frac.trt
#################
#################
# d13C by fraction and treatments

df.mean<-aggregate(d13C.value~AA.short+Fraction+Treat.Int, data=dfC, mean, na.rm=TRUE)
df.n<-aggregate(d13C.value~AA.short+Fraction+Treat.Int, data=dfC, length)
df.SD<-aggregate(d13C.value~AA.short+Fraction+Treat.Int, data=dfC, sd, na.rm=TRUE)
colnames(df.SD)[4]="SD"
df.mean<-cbind(df.mean, df.SD[4])

# replace NA for plankton SD as 0
df.mean$SD[is.na(df.mean$SD)] <- 0
df.mean$Fraction<-factor(df.mean$Fraction, levels=c("host", "symb", "plank"))
df.mean$Treat.Int<-factor(df.mean$Treat.Int, levels=c("L-NF", "L-F", "D-F", "Plank"))


## d13C just by fraction
df.mean.frac<-aggregate(d13C.value~AA.short+Fraction, data=dfC, mean, na.rm=TRUE)
df.n.frac<-aggregate(d13C.value~AA.short+Fraction, data=dfC, length)
df.SE.frac<-aggregate(d13C.value~AA.short+Fraction, data=dfC, std.error, na.rm=TRUE)
colnames(df.SE.frac)[3]="SE"

df.SE.frac[is.na(df.SE.frac)] <- 0
df.mean.frac<-cbind(df.mean.frac, df.SE.frac[3])
df.mean.frac$Fraction<-factor(df.mean.frac$Fraction, levels=c("host", "symb", "plank"))
write.csv(df.mean.frac, "output/d13C.mean.frac.csv")


######## Figures
Fig.formatting<-(theme_classic()) +
  theme(text=element_text(size=10),
        axis.line=element_blank(),
        legend.text.align = 0,
        legend.text=element_text(size=10),
        #legend.title = element_blank(),
        panel.border = element_rect(fill=NA, colour = "black", size=1),
        aspect.ratio=1, 
        axis.ticks.length=unit(0.25, "cm"),
        axis.text.y=element_text(
          margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"), colour="black", size=10), 
        axis.text.x=element_text(
          margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"), colour="black", size=8)) +
  theme(legend.key.size = unit(0.4, "cm")) +
  theme(aspect.ratio=1) +
  theme(panel.spacing=unit(c(0, 0, 0, 0), "cm"))

#######
pd <- position_dodge(0.5) #offset for error bars

d13C.CSIA_frac.trt<-ggplot(df.mean, aes(x=AA.short, y=d13C.value)) +
  geom_point(size=2, position=pd, aes(shape=Treat.Int, color=Fraction, group=Treat.Int)) +
  geom_errorbar(aes(ymin=d13C.value-SD, ymax=d13C.value+SD, color=Fraction, group=Treat.Int), 
                size=.5, width=0, position=pd) +
  ggtitle(expression(paste(delta^{13}, C[AA], " by biological fraction and treatment"))) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Nonessential-AA", x=4, y=0, color="gray40") +
  annotate(geom="text", label="Essential-AA", x=10, y=0, color="gray40") +
  coord_cartesian(ylim=c(-35, 0)) + 
  xlab("Amino Acids") +
  scale_color_manual(values=c(frac.color)) +
  ylab(expression(paste(delta^{13}, C[AA], " (\u2030, V-PDB)"))) +
  Fig.formatting
print(d13C.CSIA_frac.trt)

#ggsave("figures/carbon/d13C.CSIA_frac.trt.pdf", height=5, width=8, encod="MacRoman")
  • all d13C amino acids: showing d13C.CSIA_Trt.alone – move to Supplement
##################
# all d13C amino acids

df.mean2<-aggregate(d13C.value~AA.short+Treat.Int, data=dfC, mean, na.rm=TRUE)
df.SE2<-aggregate(d13C.value~AA.short+Treat.Int, data=dfC, na.rm=TRUE, std.error)
df.n2<-aggregate(d13C.value~AA.short+Treat.Int, data=dfC, length)
df.SE2[is.na(df.SE2)] <- 0
colnames(df.SE2)[3]="SE"
df.mean2<-cbind(df.mean2, df.SE2[3])

pd <- position_dodge(0.5) #offset for error bars

 d13C.CSIA_Trt.alone<-ggplot(df.mean2, aes(x=AA.short, y=d13C.value, group=Treat.Int)) +
  geom_errorbar(aes(ymin=d13C.value-SE, ymax=d13C.value+SE, color=Treat.Int), size=.5, width=0, position=pd) +
  geom_point(aes(color=Treat.Int, shape=Treat.Int), size=2, position=pd) +
  scale_shape_manual(values=c(19,19,19,3))+
  scale_color_manual(values=trt.color)+
  ggtitle(expression(paste(delta^{13}, C[AA], " by treatment"))) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Nonessential-AA", x=4, y=0, color="gray40") +
  annotate(geom="text", label="Essential-AA", x=10, y=0, color="gray40") +
  coord_cartesian(ylim=c(-35, 0)) + 
  xlab("Amino Acids") +
  ylab(expression(paste(delta^{13}, C[AA], " (\u2030, V-PDB)"))) +
  Fig.formatting
print(d13C.CSIA_Trt.alone)

#ggsave("figures/carbon/d13C.CSIA_Trt.alone.pdf", height=5, width=8, encod="MacRoman")
  • d13C by fraction, showing d13C.CSIA_frac – move to Supplement
# all AA pooled by fraction


df.mean3<-aggregate(d13C.value~AA.short+Fraction, data=dfC, mean, na.rm=TRUE)
df.SE3<-aggregate(d13C.value~AA.short+Fraction, data=dfC, na.rm=TRUE, std.error)
df.n3<-aggregate(d13C.value~AA.short+Fraction, data=dfC, length)
df.SE3[is.na(df.SE3)] <- 0
colnames(df.SE3)[3]="SE"
df.mean3<-cbind(df.mean3, df.SE3[3])
df.mean3$Fraction<-factor(df.mean3$Fraction, levels=c("host", "symb", "plank"))


pd <- position_dodge(0.5) #offset for error bars

d13C.CSIA_Fraction<- ggplot(df.mean3, aes(x=AA.short, y=d13C.value)) +
  geom_errorbar(aes(ymin=d13C.value-SE, ymax=d13C.value+SE, color=Fraction), 
                size=.5, width=0, position=pd) +
  geom_point(size=2,  position=pd, aes(color=Fraction, shape=Fraction)) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Nonessential-AA", x=4, y=0, color="gray40") +
  annotate(geom="text", label="Essential-AA", x=10, y=0, color="gray40") +
  ggtitle(expression(paste(delta^{13}, C[AA], " by biological fraction"))) +
  coord_cartesian(ylim=c(-35, 0)) + 
  xlab("Amino Acids") + 
  ylab(expression(paste(delta^{13}, C[AA], " (\u2030, V-PDB)"))) +
  scale_color_manual(values=frac.color) +
  scale_shape_manual(values=c(19,19,3))+
  Fig.formatting
print(d13C.CSIA_Fraction)

#ggsave("figures/carbon/d13C.CSIA_Fraction.pdf", height=5, width=8, encod="MacRoman")

Nitrogen AA

Models

Overall we see:
- Fraction effect for: Leucine, Proline, Aspartic Acid, Glutamic Acid, Tyrosine.
- Treatment effect for: Leucine

d15N.dat2<-d15N.dat[!(d15N.dat$Fraction=="plank"),] #remove plankton for now

for(i in c(11:23)){
  Y=d15N.dat2[,i]
  mod<-aov(Y~Fraction+Treat.Int, data=d15N.dat2)
  print(anova(mod), cex=0.5)
  #print(TukeyHSD(mod))
  plot(allEffects(mod), ylab=colnames(d15N.dat2)[i], cex.axis=0.5)
}
## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  8.1676  8.1676  3.3922 0.1028
## Treat.Int  2  1.8579  0.9290  0.3858 0.6919
## Residuals  8 19.2618  2.4077

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  4.2262  4.2262  1.6503 0.2349
## Treat.Int  2  1.5693  0.7846  0.3064 0.7444
## Residuals  8 20.4868  2.5609

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1 13.327 13.3269  2.6576 0.1417
## Treat.Int  2  3.612  1.8061  0.3602 0.7083
## Residuals  8 40.117  5.0147

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.0006 0.00062  0.0003 0.9860
## Treat.Int  2  1.6612 0.83058  0.4397 0.6589
## Residuals  8 15.1127 1.88908

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1 0.2248 0.22482  0.2201 0.6515
## Treat.Int  2 0.0415 0.02076  0.0203 0.9799
## Residuals  8 8.1699 1.02123

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value   Pr(>F)   
## Fraction   1 9.9952  9.9952 19.9043 0.002107 **
## Treat.Int  2 3.8088  1.9044  3.7924 0.069430 . 
## Residuals  8 4.0173  0.5022                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.3383  0.3383  0.0908 0.7708
## Treat.Int  2  3.8576  1.9288  0.5178 0.6145
## Residuals  8 29.8002  3.7250

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value    Pr(>F)    
## Fraction   1 22.9354 22.9354 28.9356 0.0006623 ***
## Treat.Int  2  4.1174  2.0587  2.5973 0.1351371    
## Residuals  8  6.3411  0.7926                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## Fraction   1 3.3328  3.3328  6.3165 0.03619 *
## Treat.Int  2 1.4198  0.7099  1.3455 0.31354  
## Residuals  8 4.2210  0.5276                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value Pr(>F)
## Fraction   1 1.1145 1.11452  2.3608 0.1630
## Treat.Int  2 0.9348 0.46741  0.9901 0.4129
## Residuals  8 3.7768 0.47210

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  1.4002 1.40019  0.5355 0.4852
## Treat.Int  2  0.8007 0.40036  0.1531 0.8605
## Residuals  8 20.9164 2.61455

## Analysis of Variance Table
## 
## Response: Y
##           Df Sum Sq Mean Sq F value  Pr(>F)  
## Fraction   1 16.163  16.163  8.9499 0.01729 *
## Treat.Int  2  0.128   0.064  0.0354 0.96532  
## Residuals  8 14.448   1.806                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## Analysis of Variance Table
## 
## Response: Y
##           Df  Sum Sq Mean Sq F value Pr(>F)
## Fraction   1  0.1051 0.10513  0.0799 0.7846
## Treat.Int  2  0.2452 0.12259  0.0931 0.9120
## Residuals  8 10.5298 1.31623

# Fraction effect for: Leucine, Proline, Aspartic Acid, Glutamic Acid, Tyrosine
# Treatment effect for: Leucine

Figures

###########
###########
# d15N.CSIA.dat long
d15N.dat.long<-read.csv("data/d15N.CSIA.long.csv")

#str(d15N.dat.long)

d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Methionine"),]
d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Norleucine"),]
d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Aminoadipic Acid"),] # remove unwanted data

d15N.dat.long$AA.short<-mapvalues(d15N.dat.long$Amino.acid, from =c("Alanine", "Aspartic acid", "Glutamic acid", "Glycine", "Isoleucine", "Leucine", "Lysine", "Phenylalanine", "Proline", "Serine", "Threonine", "Tyrosine", "Valine"), to = c("Ala", "Asp", "Glu", "Gly", "Ile", "Leu", "Lys", "Phe", "Pro", "Ser", "Thr", "Tyr", "Val"))

d15N.dat.long$AA.short<-factor(d15N.dat.long$AA.short, levels=c("Ala","Asp", "Glu", "Ile", "Leu", "Pro", "Val", "Gly", "Lys", "Ser", "Phe", "Thr", "Tyr"))

# looking at average Trophic and Source
d15N.dat.long$AA.cat<-ifelse(d15N.dat.long$AA.short=="Asp" | d15N.dat.long$AA.short=="Glu" | 
                               d15N.dat.long$AA.short=="Ala" | d15N.dat.long$AA.short=="Ile" | 
                               d15N.dat.long$AA.short=="Leu" | d15N.dat.long$AA.short=="Val" | 
                               d15N.dat.long$AA.short=="Pro", "Troph", "Source")

d15N.dat.long$Treat.Int<-factor(d15N.dat.long$Treat.Int, levels=c("L-NF", "L-F", "D-F", "Plank"))

dfN<-d15N.dat.long
  • all AA pooled by fraction, showing d15N.CSIA_Fraction
######## Figures
pd <- position_dodge(0.5) #offset for error bars

df.mean<-aggregate(d15N.value~AA.short+Fraction, data=dfN, mean, na.rm=TRUE)
df.n<-aggregate(d15N.value~AA.short+Fraction, data=dfN, length)
df.SE<-aggregate(d15N.value~AA.short+Fraction, data=dfN, std.error, na.rm=TRUE)
df.SE[is.na(df.SE)] <- 0
colnames(df.SE)[3]="SE"
df.mean<-cbind(df.mean, df.SE[3])
df.mean$Fraction<-factor(df.mean$Fraction, levels=c("host", "symb", "plank"))
write.csv(df.mean, "output/d15N.frac.meanse.csv")

Fig.formatting<-(theme_classic()) +
  theme(text=element_text(size=10),
        axis.line=element_blank(),
        legend.text.align = 0,
        legend.text=element_text(size=10),
        #legend.title = element_blank(),
        panel.border = element_rect(fill=NA, colour = "black", size=1),
        aspect.ratio=1, 
        axis.ticks.length=unit(0.25, "cm"),
        axis.text.y=element_text(
          margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"), colour="black", size=10), 
        axis.text.x=element_text(
          margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"), colour="black", size=8)) +
  theme(legend.key.size = unit(0.4, "cm")) +
  theme(aspect.ratio=1) +
  theme(panel.spacing=unit(c(0, 0, 0, 0), "cm"))

######
# all AA pooled by fraction
d15N.CSIA_Fraction<-ggplot(df.mean, aes(x=AA.short, y=d15N.value)) +
  geom_errorbar(aes(ymin=d15N.value-SE, ymax=d15N.value+SE, color=Fraction), 
                size=.5, width=0, position=pd) +
  geom_point(size=2, position=pd, aes(color=Fraction, shape=Fraction)) +
  scale_shape_manual(values=c(19,19,3))+
  ggtitle(expression(paste(delta^{15}, N[AA], " by biological fraction"))) +
  coord_cartesian(ylim=c(-5, 15)) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Trophic-AA", x=4, y=15, color="gray40") +
  annotate(geom="text", label="Source-AA", x=10, y=15, color="gray40") +
  xlab("Amino Acids") + 
  ylab(expression(paste(delta^{15}, N[AA], " (\u2030, Air)"))) +
  scale_color_manual(values=frac.color)+
  Fig.formatting
print(d15N.CSIA_Fraction)

#ggsave("figures/nitrogen/d15N.CSIA_Fraction.pdf", height=5, width=8, encod="MacRoman")
  • Fraction and treatment, showing d15N.CSIA_frac.trt
#################
df.mean<-aggregate(d15N.value~AA.short+Fraction+Treat.Int, data=dfN, mean, na.rm=TRUE)
df.n<-aggregate(d15N.value~AA.short+Fraction+Treat.Int, data=dfN, length)
df.SD<-aggregate(d15N.value~AA.short+Fraction+Treat.Int, data=dfN, sd, na.rm=TRUE)
colnames(df.SD)[4]="SD"

df.SD[is.na(df.SD)] <- 0
df.mean<-cbind(df.mean, df.SD[4])
df.mean$Fraction<-factor(df.mean$Fraction, levels=c("host", "symb", "plank"))
df.mean$Treat.Int<-factor(df.mean$Treat.Int, levels=c("L-NF", "L-F", "D-F", "Plank"))

d15N.CSIA_frac.trt<-ggplot(df.mean, aes(x=AA.short, y=d15N.value)) +
  geom_point(size=2, aes(shape=Treat.Int, color=Fraction, group=Treat.Int), position=pd) +
  geom_errorbar(aes(ymin=d15N.value-SD, ymax=d15N.value+SD, group=Treat.Int, color=Fraction), 
                size=.5, width=0, position=pd) +
  ggtitle(expression(paste(delta^{15}, N[AA], " by biological fraction, treatment"))) +
  coord_cartesian(ylim=c(-5, 15)) + 
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Trophic-AA", x=4, y=15, color="gray40") +
  annotate(geom="text", label="Source-AA", x=10, y=15, color="gray40") +
  xlab("Amino Acids") +
  scale_color_manual(values=frac.color) +
  ylab(expression(paste(delta^{15}, N[AA], " (\u2030, Air)"))) +
  Fig.formatting
print(d15N.CSIA_frac.trt)

#ggsave("figures/nitrogen/d15N.CSIA_frac.trt.pdf", height=5, width=8, encod="MacRoman")
  • all amino acids, showing d15N.CSIA_Trt.alone.pdf
##################
# all d15N amino acids

df.mean2<-aggregate(d15N.value~AA.short+Treat.Int, data=dfN, mean, na.rm=TRUE)
df.n2<-aggregate(d15N.value~AA.short+Treat.Int, data=dfN, length)
df.SE2<-aggregate(d15N.value~AA.short+Treat.Int, data=dfN, na.rm=TRUE, std.error)
df.SE2[is.na(df.SE2)] <- 0
colnames(df.SE2)[3]="SE"
df.mean2<-cbind(df.mean2, df.SE2[3])

d15N.CSIA_Trt.alone<-ggplot(df.mean2, aes(x=AA.short, y=d15N.value, group=Treat.Int)) +
  geom_errorbar(aes(ymin=d15N.value-SE, ymax=d15N.value+SE, color=Treat.Int), size=.5, width=0, position=pd) +
  geom_point(aes(color=Treat.Int, shape=Treat.Int), size=2, position=pd) +
  ggtitle(expression(paste(delta^{15}, N[AA], " by treatment"))) +
  coord_cartesian(ylim=c(-5, 15)) + 
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Trophic-AA", x=4, y=15, color="gray40") +
  annotate(geom="text", label="Source-AA", x=10, y=15, color="gray40") +
  xlab("Amino Acids") +
  scale_color_manual(values=trt.color) +
  scale_shape_manual(values=c(19,19,19,3))+
  ylab(expression(paste(delta^{15}, N[AA], " (\u2030, Air)"))) +
  Fig.formatting
print(d15N.CSIA_Trt.alone)

#ggsave("figures/nitrogen/d15N.CSIA_Trt.alone.pdf", height=5, width=8, encod="MacRoman")
  • all source and trophic AA, showing d15N.CSIA_TrSo supplement
##################
# all source and trophic) AA
AA.means<-aggregate(d15N.value~AA.cat+Treat.Int+Fraction, data=dfN, mean, na.rm=TRUE)
AA.n<-aggregate(d15N.value~AA.cat+Treat.Int+Fraction, data=dfN, length)
AA.se<-aggregate(d15N.value~AA.cat+Treat.Int+Fraction, data=dfN, std.error, na.rm=TRUE)
colnames(AA.se)[4]="SE"
AA.means<-cbind(AA.means, AA.se[4])
AA.means$Fraction<-factor(AA.means$Fraction, levels=c("host", "symb", "plank"))
AA.means$Treat.Int<-factor(AA.means$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))

ggplot(AA.means, aes(x=Treat.Int, y=d15N.value, shape=AA.cat, color=Fraction)) +
  geom_errorbar(aes(ymin=d15N.value-SE, ymax=d15N.value+SE, shape=AA.cat, color=Fraction), 
                size=.5, width=0, position=pd) +
  geom_point(aes(shape=AA.cat, color=Fraction), size=3, position=pd) +
  ggtitle(expression(paste(delta^{15}, N[AA], " by biological fraction, Tr/So-AA"))) +
  coord_cartesian(ylim=c(0, 12)) + 
  scale_x_discrete(name ="Treatments", 
                   labels=c("Dark\nFed", "Light\nFed", "Light\nNot Fed")) +
  scale_color_manual(values=c("coral", "springgreen3",  "skyblue3")) +
  ylab(expression(paste(delta^{15}, N[AA], " (\u2030, Air)"))) +
  Fig.formatting

#ggsave("figures/nitrogen/d15N.CSIA_TrSo.pdf", height=5, width=8, encod="MacRoman")
Trophic position and proxy

Trophic position using trophic AA gultamic acid (Glu) and source amino acid phenylalanine (Phe), following Chikaraishi et al. 2009

\(Trophic~position~(TP){_C}{_S}{_I}{_A}= [(δ{^1}{^5}N{_T}{_r}{_p}~-~δ{^1}{^5}N{_S}{_r}{_c})-B/~TDF{_A}{_A} +1\)

  • Trophic Position, showing TP.glu.phe
###
# scatter of glutamic.acid vs. phenylalanine
 
       
### ### ### 
### ### ### trophic position using trophic (Glu) and source (Phe) AA, Chikaraishi et al. 2009

d15N.dat # dataframe here
# glu = trophic AA (changing with food,  show enrichment realtive to source
# phe = source AA (showlittle change with increasing trophic position, reflect d15N baseline)
# beta = 3.4 (difference in d15N values among trophic and source AAs in primary producers, @ TP=1)
# TDFAA = trophic discrimination factor: mean 15N enrichment of >=1 trophic vs. source AA per trophic level
 
d15N.dat<-d15N.dat %>% mutate(TP = ((Glutamic.acid - Phenylalanine - 3.4)/7.6) +1)

# run a model
TP.df<-d15N.dat
TP.df<-TP.df[!(TP.df$Fraction=="plank"),] # remove plankton
anova(lm(TP~Fraction+Treat.Int, data=TP.df)) # no difference


df.mean<-aggregate(TP~Treat.Int+Fraction, data=d15N.dat, mean, na.rm=TRUE)
df.n<-aggregate(TP~Treat.Int+Fraction, data=d15N.dat, length)
df.SD<-aggregate(TP~Treat.Int+Fraction, data=d15N.dat, sd, na.rm=TRUE)
colnames(df.SD)[3]="SD"
df.mean<-cbind(df.mean, df.SD[3])
df.mean$Fraction<-factor(df.mean$Fraction, levels=c("host", "symb", "plank"))
df.mean$Treat.Int<-factor(df.mean$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))

TP<-ggplot(df.mean, aes(x=Treat.Int, y=TP)) +
  geom_errorbar(aes(ymin=TP-SD, ymax=TP+SD, color=Fraction), 
                size=.5, width=0, position=pd) +
  geom_point(size=2,  position=pd, aes(color=Fraction, shape=Fraction)) +
  ggtitle("Chikaraishi trophic position") +
  coord_cartesian(ylim=c(0, 3)) +
  scale_x_discrete(name ="Treatments", 
                   labels=c("Dark\nFed", "Light\nFed", "Light\nNot Fed", "Plankton")) +
  ylab(expression(paste("TP "~delta^{15}, N[Glu-Phe], " (\u2030, Air)"))) +
  scale_shape_manual(values=c(19,19,3))+
  scale_color_manual(values=frac.color) +
  Fig.formatting
#print(TP)
#ggsave("figures/nitrogen/TP.glu.phe.pdf", height=5, width=8, encod="MacRoman")
Sum V

Calculate Sum-V, McCarthy et al. 2007. The sum-V parameter is a proxy for total heterotrophic resynthesis. It is defined as the average deviation in the d15N values of the trophic amino acids Ala, Asp, Glu, Ile, Leu, and Pro.

  • showing d15N.sumV.CSIA move to supplement
###########
###########
# d15N.CSIA.dat long
d15N.dat.long<-read.csv("data/d15N.CSIA.long.csv")

#str(d15N.dat.long)

d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Methionine"),]
d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Norleucine"),]
d15N.dat.long<-d15N.dat.long[!(d15N.dat.long$Amino.acid=="Aminoadipic Acid"),] # remove unwanted data

d15N.dat.long$AA.short<-mapvalues(d15N.dat.long$Amino.acid, from =c("Alanine", "Aspartic acid", "Glutamic acid", "Glycine", "Isoleucine", "Leucine", "Lysine", "Phenylalanine", "Proline", "Serine", "Threonine", "Tyrosine", "Valine"), to = c("Ala", "Asp", "Glu", "Gly", "Ile", "Leu", "Lys", "Phe", "Pro", "Ser", "Thr", "Tyr", "Val"))

d15N.dat.long$AA.short<-factor(d15N.dat.long$AA.short, levels=c("Ala","Asp", "Glu", "Ile", "Leu", "Pro", "Val", "Gly", "Lys", "Ser", "Phe", "Thr", "Tyr"))

# looking at average Trophic and Source
d15N.dat.long$AA.cat<-ifelse(d15N.dat.long$AA.short=="Asp" | d15N.dat.long$AA.short=="Glu" | 
                               d15N.dat.long$AA.short=="Ala" | d15N.dat.long$AA.short=="Ile" | 
                               d15N.dat.long$AA.short=="Leu" | d15N.dat.long$AA.short=="Val" | 
                               d15N.dat.long$AA.short=="Pro", "Troph", "Source")

d15N.dat.long$Treat.Int<-factor(d15N.dat.long$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))

dfN<-d15N.dat.long


###########################
###########################
###########################
# dfN is dataframe
sV.df<-dfN[!(dfN$AA.short=="Thr"), ] # not good source, remove here

# make dataframe for AA, that with su deviance = sum-V
sV.df<-sV.df[c(sV.df$AA.short=="Ala" | sV.df$AA.short=="Glu" | sV.df$AA.short=="Asp" | 
                  sV.df$AA.short=="Ile" | sV.df$AA.short=="Leu" | sV.df$AA.short=="Pro"),]

#write.csv(sV.df, "sumV.csv")

sumVdf<-read.csv("data/sumV.csv")
sumVdf$Fraction<-factor(sumVdf$Fraction, levels=c("host", "symb", "plank"))
sumVdf$Treat.Int<-factor(sumVdf$Treat.Int, levels=c("L-NF", "L-F", "D-F", "plank"))


######## model
sumVdf.mod<-sumVdf[!(sumVdf$Fraction=="plank"),] # remove plankton
anova(lm(sumV~Fraction + Treat.Int, data=sumVdf.mod)) # no difference
######## 


sumVdf.mean<-aggregate(sumV~AA.short+AA.cat+Fraction+Treat.Int, data=sumVdf, mean, na.rm=TRUE)
sumVdf.n<-aggregate(sumV~AA.short+AA.cat+Fraction+Treat.Int, data=sumVdf, length)
sumVdf.sd<-aggregate(sumV~AA.short+AA.cat+Fraction+Treat.Int, data=sumVdf, sd, na.rm=TRUE)
sumVdf<-cbind(sumVdf.mean, sumVdf.sd[5])
colnames(sumVdf)[5]<-"mean.sumV"
colnames(sumVdf)[6]="SD"
sumVdf[is.na(sumVdf)] <- 0

pd <- position_dodge(0.7) #offset for error bars and columns

sumV<-ggplot(sumVdf, aes(x=Treat.Int, y=mean.sumV)) +
  geom_point(aes(color=Fraction), size=2, position=pd) +
  geom_errorbar(aes(ymin=mean.sumV-SD, ymax=mean.sumV+SD, color=Fraction), 
                size=.5, width=0, position=pd) +
  coord_cartesian(ylim=c(0, 3))+ 
  ggtitle(expression(paste("Sum-V ", delta^{15}, N[AA]))) +
  scale_color_manual(values=frac.color) +
  scale_x_discrete(name ="Treatments", 
                   labels=c("Dark\nFed", "Light\nFed", "Light\nNot Fed", "Plankton")) +
  ylab(expression(paste(delta^{15}, N[Sum-V], " (\u2030, Air)"))) +
  Fig.formatting
#print(sumV)
#ggsave("figures/nitrogen/d15N.sumV.CSIA.pdf", height=5, width=8, encod="MacRoman")
Weighted means

These are the weighted means for trophic and source AA following Bradley et al. 2015. Weighted mean AA δ15N values.

  • weighted means, showing wt.mean.d15N.CSIA supplement
###########################
##################
#########

df.mean<-aggregate(d15N.value~AA.short+AA.cat+Fraction+Treat.Int, data=dfN, mean, na.rm=TRUE)
df.n<-aggregate(d15N.value~AA.short+AA.cat+Fraction+Treat.Int, data=dfN, length)
df.SD<-aggregate(d15N.value~AA.short+AA.cat+Fraction+Treat.Int, data=dfN, sd, na.rm=TRUE)
colnames(df.SD)[5]="SD"
df.mean<-cbind(df.mean, df.SD[5])
df.mean$mean.sd<-(df.mean$d15N.value/df.mean$SD)
df.mean$inv.sd<-(1/df.mean$SD)
# write.csv(df.mean, "wtmeans.csv") # use this to calculate weighted mean
# weighted mean is sum(mean.sd/inv.sd) for trophic AA, same for source AA
# delta.Tr.So (below) is difference in (weighted mean) Trophic AA - Source AA for host or symb, per treatment

#########
wt.mean<-read.csv("data/wt.means.d15N.csv")
wt.mean.df<-aggregate(wt.mean~AA.cat+Fraction+Treat.Int, data=wt.mean, mean, na.rm=TRUE)
SD<-aggregate(wt.SD~AA.cat+Fraction+Treat.Int, data=wt.mean, mean, na.rm=TRUE); colnames(SD)[4]<-"wt.SD"
wt.mean.df<-cbind(wt.mean.df, SD[4])


######## model
wt.mean.mod<-wt.mean[!(wt.mean$Fraction=="plank"),]
anova(lm(wt.mean~Fraction + Treat.Int, data=wt.mean.mod)) # no difference
######## 


pd <- position_dodge(0.5) #offset for error bars
ggplot(wt.mean.df, aes(x=Treat.Int, y=wt.mean)) +
  geom_point(aes(color=Fraction, shape=AA.cat), size=3, position=pd) +
  geom_errorbar(aes(ymin=wt.mean-wt.SD, ymax=wt.mean+wt.SD, color=Fraction, shape=AA.cat), 
                size=.5, width=0, position=pd) +
  coord_cartesian(ylim=c(0, 12))+ 
  ggtitle(expression(paste("Weighted Mean ", delta^{15}, N[AA]))) +
  scale_color_manual(values=c("coral", "springgreen3")) +
  scale_x_discrete(name ="Treatments", 
                   labels=c("Dark\nFed", "Light\nFed", "Light\nNot Fed")) +
  ylab(expression(paste(delta^{15}, N[AA], " (\u2030, Air)"))) +
  Fig.formatting
*Figure S4*. δ15NAA weighted means for trophic and source amino acids according to coral tissue fractions (host, symbiont) and experimental nutrition-treatments. Values are mean ± SD (n=2).

Figure S4. δ15NAA weighted means for trophic and source amino acids according to coral tissue fractions (host, symbiont) and experimental nutrition-treatments. Values are mean ± SD (n=2).

ggsave("figures/Fig S4.wt.mean.d15N.CSIA.pdf", height=5, width=8, encod="MacRoman")

COMBINED FIGURES

Figure 2– PCA.combined

#### compile the 4 PCA ###
library("cowplot")
plot_grid(PC.fig3.C.frac, PC.fig4.N.frac, PC.fig1.C.trt, PC.fig2.N.trt, ncol = 2)
*Figure 2*. Principal component analysis of carbon (left) and nitrogen (right) isotope values of individual amino acids in corals, Symbiodiniaceae, and a pooled plankton sample in relation to tissue fraction (top) and treatments (bottom). Ellipses represent 90% standard deviation with arrows for individual amino acids being significant (p<0.05) correlation vectors.

Figure 2. Principal component analysis of carbon (left) and nitrogen (right) isotope values of individual amino acids in corals, Symbiodiniaceae, and a pooled plankton sample in relation to tissue fraction (top) and treatments (bottom). Ellipses represent 90% standard deviation with arrows for individual amino acids being significant (p<0.05) correlation vectors.

ggsave("figures/Fig 2.PCAs.pdf", height=8, width=11, encod="MacRoman")

######

Figure xx– LDA.combined

#### compile the 4 LDA ###
plot_grid(LDA.C.NEAA, LDA.N.Tr, LDA.C.EAA, LDA.N.Sr, ncol = 2)

ggsave("figures/Fig x.LDAs.pdf", height=6, width=7, encod="MacRoman")

######

Figure 3– AA.frac-by-treatment combined

leg1 <- get_legend(
  # create some space to the left of the legend
  d13C.CSIA_frac.trt + theme(legend.box.margin = margin(0, 0, 0, 12)))

AA.frac.trt<- plot_grid(d13C.CSIA_frac.trt + ggtitle("")+ 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                            annotate(geom="text", size=3, label="(a)", x=1, y=0, color="black"), 
                       d15N.CSIA_frac.trt + ggtitle("") + 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                       annotate(geom="text", size=3, label="(b)", x=1, y=15, color="black"),
                       ncol=2,nrow=1)
plot_grid(AA.frac.trt, leg1, rel_widths = c(8, 1)) # legend  1/8 size as first obj.
*Figure 3*. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank) and in host and symbiont tissues in response to nutrition treatment: Dark-Fed (D-F), Light-Fed (L-F), and Light-Not Fed (L-NF). Values are mean ± SD (n=2), except for the plankton sample (n=1).

Figure 3. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank) and in host and symbiont tissues in response to nutrition treatment: Dark-Fed (D-F), Light-Fed (L-F), and Light-Not Fed (L-NF). Values are mean ± SD (n=2), except for the plankton sample (n=1).

dev.copy(pdf, "figures/Fig 3.AA.frac.trt.pdf", width = 10, height = 5, encod="MacRoman")
dev.off()

Supplemental Figure S1– AA.trt plot

leg2 <- get_legend(
  # create some space to the left of the legend
d13C.CSIA_Trt.alone + theme(legend.box.margin = margin(0, 0, 0, 12)))

AA.trt<- plot_grid(d13C.CSIA_Trt.alone + ggtitle("")+ 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                            annotate(geom="text", size=3, label="(a)", x=1, y=0, color="black"), 
                       d15N.CSIA_Trt.alone + ggtitle("") + 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                       annotate(geom="text", size=3, label="(b)", x=1, y=15, color="black"),
                       ncol=2,nrow=1)
plot_grid(AA.trt, leg2, rel_widths = c(8, 1)) # legend  1/8 size as first obj.
*Figure S1*. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank). Values are mean ± SD (n=2), except for the plankton sample (n=1).

Figure S1. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank). Values are mean ± SD (n=2), except for the plankton sample (n=1).

dev.copy(pdf, "figures/Fig S1.AA.trt.pdf", width = 10, height = 5, encod="MacRoman")
dev.off()

Supplemental Figure S2– AA.frac combined

leg3 <- get_legend(
  # create some space to the left of the legend
d13C.CSIA_Fraction + theme(legend.box.margin = margin(0, 0, 0, 12)))

AA.trt<- plot_grid(d13C.CSIA_Fraction + ggtitle("")+ 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                            annotate(geom="text", size=3, label="(a)", x=1, y=0, color="black"), 
                       d15N.CSIA_Fraction + ggtitle("") + 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                       annotate(geom="text", size=3, label="(b)", x=1, y=15, color="black"),
                       ncol=2,nrow=1)
plot_grid(AA.trt, leg3, rel_widths = c(8, 1)) # legend  1/8 size as first obj.
*Figure S2*. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank). Values are mean ± SE (n=6), except for the plankton sample (n=1).

Figure S2. (a) Carbon and (b) nitrogen isotope analysis of individual amino acids in coral (host), symbiont algae (symb), and a pooled plankton sample (plank). Values are mean ± SE (n=6), except for the plankton sample (n=1).

dev.copy(pdf, "figures/Fig S2.AA.frac.pdf", width = 10, height = 5, encod="MacRoman")
dev.off()

Supplemental figure S3– TP and Sum V combined

leg4 <- get_legend(
  # create some space to the left of the legend
  TP + theme(legend.box.margin = margin(0, 0, 0, 12)))

TP.sumV.plots<- plot_grid(TP + ggtitle("")+ 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                            annotate(geom="text", size=2.2, label="(a)", x=0.7, y=3, color="black"), 
                       sumV + ggtitle("") + 
                            theme(legend.position = "none",
                                  axis.text.x=element_text(size=7),  
                                  axis.text.y=element_text(size=7), 
                                  axis.title.x=element_text(size=7),
                                  axis.title.y=element_text(size=7)) +
                       annotate(geom="text", size=2.2, label="(b)", x=0.7, y=3, color="black"),
                       ncol=2,nrow=1)
plot_grid(TP.sumV.plots, leg4, rel_widths = c(6, 1)) # legend  1/3 size as first obj.
*Figure S3*. (a) Trophic position and (b) sum-V calculations for nitrogen isotope analysis of individual amino acids in coral (host) and symbiont algae (symb) in response to nutrition treatment and in relation to a pooled plankton sample (plank). Values are mean ± SD (n=2), except for the plankton sample (n=1).

Figure S3. (a) Trophic position and (b) sum-V calculations for nitrogen isotope analysis of individual amino acids in coral (host) and symbiont algae (symb) in response to nutrition treatment and in relation to a pooled plankton sample (plank). Values are mean ± SD (n=2), except for the plankton sample (n=1).

dev.copy(pdf, "figures/Fig S3.TP.sumV.pdf", width = 7, height = 5, encod="MacRoman")
dev.off()

LDA for normalized Pacific data

Mean-normalized data is important for comparing across species, times, or locations. This is accomplished by taking the across sample mean for the amino acid (AA) of choice, then subtracting the raw AA value from the mean. We did this for the essential AA (EAA) of carbon: Leucine, Isoleucine, Phenylalanine, Threonine, Lysine, Valine.

Uses linear discrimination analyses (LDA) of the mean-normalized EAA in symbiont and plankton+POM from Oahu (this study) and those reported in Fox et al (2019, FuncEcol) to act as training data for sources of autotrophic vs. heterotrophic nutrition. The training data is then applied to the coral species in the two studies (M. capitata and Pocillopora meandrina) to assign coral IDs, asking if the corals align with either autotrophic or heterotrophic groups.

Combine the data from Oahu and Palmyra ### d13C-AA data from Fox et al

##### Palmyra data
Fox.data<-read.csv("data/Palmyra_AAd13C.csv")

# rename a column
names(Fox.data)[names(Fox.data)=="group"] <- "Fraction"

# rename a level
Fox.data$Fraction<-  revalue(Fox.data$Fraction, c("Animal"="host.Pal", "Zoox"="symb.Pal", 
                                "Plankton"="plank.Pal", "POM"="POM.Pal"))
       
# select columns
Fox.data<- Fox.data %>%
  select(Location, Species, Fraction, Ala13C, Gly13C, Thr13C, Ser13C, Val13C, Leu13C, Ile13C, Pro13C, Asp13C, Glu13C, Phe13C, Tyr13C, Lys13C)

# rename AA

Fox.data<-  plyr::rename(Fox.data, c("Ala13C"="Ala", "Gly13C"="Gly", "Thr13C" = "Thr", 
                                      "Ser13C" = "Ser", "Val13C" = "Val", "Leu13C" = "Leu",
                                    "Ile13C" = "Ile", "Pro13C"= "Pro", "Asp13C" = "Asp",
                                     "Glu13C" = "Glu", "Phe13C" = "Phe", "Tyr13C" = "Tyr", "Lys13C" = "Lys"))

#### Kaneohe, Oahu data
Wall.data<-d13C.dat

# add a Location column
Wall.data$Location<- "Oahu"

# rename a level
Wall.data$Fraction<-  revalue(Wall.data$Fraction, c("host"="host.HI", "symb"="symb.HI", 
                                "plank"="plank.HI"))

# select columns
Wall.data<-Wall.data %>% 
  select(Location, Species, Fraction, Alanine, Glycine, Threonine, Serine, Valine, Leucine, Isoleucine, Proline, Aspartic.acid, Glutamic.acid, Phenylalanine, Tyrosine, Lysine)

# make names the same for both df
Wall.data<- plyr::rename(Wall.data, c("Alanine"="Ala", "Glycine"="Gly", "Threonine" = "Thr", 
                                      "Serine" = "Ser", "Valine" = "Val", "Leucine" = "Leu",
                                    "Isoleucine" = "Ile", "Proline"= "Pro", "Aspartic.acid" = "Asp",
                                     "Glutamic.acid" = "Glu", "Phenylalanine" = "Phe", 
                                    "Tyrosine" = "Tyr", "Lysine" = "Lys"))

# combine the dataframes
Pacific.AA<-rbind(Fox.data, Wall.data)
Pacific.AA$Fraction<-factor(Pacific.AA$Fraction, levels=c("host.Pal", "host.HI", "symb.Pal", "symb.HI",
                            "plank.Pal", "plank.HI", "POM.Pal"))

Run LDA analysis as performed in Fox et al. 

######## For manuscript

####### using normalized data 
####### run LDA with 2 sources: (1) plankton+POM, (2) symbiont Palmyra 
####### use the 2 sources as training data for Hawaii 
####### display points according to location (Palmyra or Hawaii)  

##########
###########

### Raw data = 'Pacific.AA'
# LDA palmyra POM + plank, with Hawaii dataset

# 6 EAA
Pacific.EAA.df<- Pacific.AA %>% 
  select(Location, Species, Fraction, Leu, Ile, Phe, Thr, Lys, Val)


###### ###### ###### ###### ###### 
###### NORMALIZING AAESS DATA BY Sample MEAN  (mean of all AA d13C) - raw individual AAd13C value

# raw compiled data is 'Pacific.EAA.df'
Pac.ess.norm<-Pacific.EAA.df

#make ID column to run the normalization
Pac.ess.norm$ID<-1:nrow(Pac.ess.norm)

for(i in 1:length(Pac.ess.norm$ID)){
  Pac.ess.norm$Ile.n[i] <- (Pac.ess.norm$Ile[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
  Pac.ess.norm$Leu.n[i] <- (Pac.ess.norm$Leu[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
  Pac.ess.norm$Lys.n[i] <- (Pac.ess.norm$Lys[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
  Pac.ess.norm$Phe.n[i] <- (Pac.ess.norm$Phe[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
  Pac.ess.norm$Thr.n[i] <- (Pac.ess.norm$Thr[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
  Pac.ess.norm$Val.n[i] <- (Pac.ess.norm$Val[i]-mean(as.numeric(Pac.ess.norm[i,4:9])))
}

Pac.ess.norm<-Pac.ess.norm[,c(1:3,10:16)] # drop raw columns and reorder

############### 
############### Normalized LDA data is 'Pac.ess.norm.df'

# add new column of factors
Pac.ess.norm$Fraction.grouped<-Pac.ess.norm$Fraction

#rename these factors to animal, symbiont, plankton, POM
Pac.ess.norm$Fraction.grouped<-revalue(Pac.ess.norm$Fraction.grouped,
                                                    c("host.Pal"="animal", "host.HI"="animal",
                                                      "symb.Pal"="symbiont", "symb.HI"="symbiont",
                                                      "plank.Pal"="plankton", "plank.HI"="plankton", 
                                                      "POM.Pal"="POM"))

#reorder
Pac.ess.norm.df<-Pac.ess.norm[,c(1:3,11,4:10)]


# separate out animal

# plankton, POM, symb = "zp"
Pac.EAA.norm.zp<-
  Pac.ess.norm.df[!(Pac.ess.norm.df$Fraction.grouped=="animal"),] 

# host animal = "ho"
Pac.EAA.norm.ho<-
  Pac.ess.norm.df[(Pac.ess.norm.df$Fraction.grouped=="animal"),]

# drop factor levels
Pac.EAA.norm.zp<-droplevels(Pac.EAA.norm.zp)
Pac.EAA.norm.ho<-droplevels(Pac.EAA.norm.ho)

# remove ID columns for now
Pac.EAA.frac.norm.zp<-Pac.EAA.norm.zp[,c(-1:-3,-5)]
Pac.EAA.frac.norm.ho<-Pac.EAA.norm.ho[,c(-1:-3,-5)]

############
############ training for leave one out: how well can we estimate the sources?
# with CV = true, results for classes and posteriors are for cross validation (CV, leave one out)
LDA.Pac.EAA.frac.norm.zp <- lda(Fraction.grouped ~ Ile.n + Leu.n + Lys.n + Phe.n + Thr.n + Val.n, data = Pac.EAA.frac.norm.zp, CV = TRUE)

# create a table which compares the classifcation of the LDA model to the actual spp
ct.prod.norm <- table(Pac.EAA.frac.norm.zp$Fraction.grouped, LDA.Pac.EAA.frac.norm.zp$class)

# total percent of samples correctly classified is the sum of the diagonal of this table
sum(diag(prop.table(ct.prod.norm))) #71% effective
## [1] 0.7142857
# what % of each species is being correctly classified
diag(prop.table(ct.prod.norm, 1)) # symbionts 100% classified, plankton 89%
## symbiont plankton      POM 
##     1.00     0.60     0.25
# create a training lda function from the source data - use this to classify the coral hosts
training.EAA.norm.samples <- lda(Fraction.grouped ~ Ile.n + Leu.n + Lys.n + Phe.n + Thr.n + Val.n, data = Pac.EAA.frac.norm.zp)

#examine coefficents of the discriminants to determine AAs contributing to groups seperation
training.EAA.norm.samples$scaling # most for Valine > Leucine > Isoleucine > Phenylalanine
##                LD1         LD2
## Ile.n -0.505236200  0.73939336
## Leu.n  0.547650386  0.33476977
## Lys.n  0.001763107  0.32016526
## Phe.n -0.348097550 -0.41508277
## Thr.n -0.122020249 -0.22064176
## Val.n  0.641733096  0.06041539
# create a dataframe with these LDA coordinates
datPred.norm.zp <- data.frame(Fraction.grouped=Pac.EAA.frac.norm.zp$Fraction.grouped,
                                   predict(training.EAA.norm.samples)$x) #create data.frame
datPred.norm.zp$ID<-Pac.EAA.norm.zp$ID

# predict the coral animal fractions based on ess
host.norm.res <- predict(training.EAA.norm.samples, Pac.EAA.frac.norm.ho) # 6 classified as plankton-POM

#save the predicted coordinates 
datPred2.norm.ho <- data.frame(Fraction.grouped='animal', host.norm.res$x)
datPred2.norm.ho$ID<-Pac.EAA.norm.ho$ID

# add to the original animal dataframe which individual got classified as what:
Pac.EAA.norm.ho$class <- host.norm.res$class #--- only 2 classified as non-symb

# merge the source and coral animal dataframes for plotting
datPred3.norm.Pac <- rbind(datPred.norm.zp, datPred2.norm.ho) 

#re-attach  medata by merging with ID
# original df with palmyra corals and zoox dropped = "Pac.EAA.frac.df"
EAA.frac.LD.norm.meta<-merge(datPred3.norm.Pac, Pac.ess.norm.df, by="ID")
names(EAA.frac.LD.norm.meta)[names(EAA.frac.LD.norm.meta)=="Fraction.grouped.x"] <- "Fraction.grouped"

#remove redundant group
EAA.frac.LD.norm.meta<-EAA.frac.LD.norm.meta[,-8]

EAA.frac.LD.norm.meta$Fraction.source2<-EAA.frac.LD.norm.meta$Fraction.grouped
EAA.frac.LD.norm.meta$Fraction.source2<-revalue(EAA.frac.LD.norm.meta$Fraction.source2,
                                                     c("POM"="plankton"))
EAA.frac.LD.norm.meta<-droplevels(EAA.frac.LD.norm.meta)

# for ellipses
dat_ell.norm.EAA <- data.frame()
for(g in levels(EAA.frac.LD.norm.meta$Fraction.source2)){
dat_ell.norm.EAA <- rbind(dat_ell.norm.EAA,
            cbind(as.data.frame(with
                                (EAA.frac.LD.norm.meta[EAA.frac.LD.norm.meta$Fraction.source2==g,], 
                                         ellipse(cor(LD1, LD2), 
                                         scale=c(sd(LD1),sd(LD2)), 
                                         centre=c(mean(LD1),mean(LD2))))), Fraction.source2=g))
}

# no ellipse drawn for animal
dat_ell.norm.EAA.source<-dat_ell.norm.EAA[!(dat_ell.norm.EAA$Fraction.source2=="animal"),]

# add back Location column
EAA.frac.LD.norm.meta$Location<-Pac.ess.norm.df$Location

# order factor
EAA.frac.LD.norm.meta$Fraction.grouped<-factor(EAA.frac.LD.norm.meta$Fraction.grouped,
                                                    levels=c("animal", "symbiont", "plankton", "POM"))

# Fraction colors
frac.color<-c("coral", "springgreen3", "steelblue1", "skyblue4")
LDA.EAA.frac.norm<-ggplot(EAA.frac.LD.norm.meta, aes(LD1, LD2)) +
  geom_point(aes(color = Fraction.grouped, shape=Location), size=2)+
  scale_color_manual(values=frac.color) +
  scale_shape_manual(values=c(1,16))+
  geom_path(data=dat_ell.norm.EAA.source, aes(x=x,y=y,color=Fraction.source2),
            size=0.5,linetype=2, show.legend=FALSE)  +
  theme(axis.ticks.length=unit(0.25, "cm"), 
        axis.text.y=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")),
        axis.text.x=element_text(margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm"))) +
  theme(text = element_text(size=8)) +
  theme(legend.text=element_text(size=10), legend.key = element_blank()) +
  theme(panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank(),
      panel.background = element_blank(), 
      axis.line = element_line(colour = "black",  size=0.5))



print(LDA.EAA.frac.norm)
*Figure 4*. Linear discriminant analysis of carbon isotope fingerprints using mean-normalized values of six essential amino acids (isoleucine, leucine, lysine, phenylalanine, threonine, tyrosine, valine). Ellipses represent 95% confidence ellipses for each nutrition group (autotrophy [symbiont] or heterotrophy [plankton-POM). Hawaii data are host (n=6), symbiont (n=6) and plankton (n=1); Palmyra data are host (n = 19), symbionts (n=11), plankton (n=9) and POM (n=8) (Fox et al. 2019).

Figure 4. Linear discriminant analysis of carbon isotope fingerprints using mean-normalized values of six essential amino acids (isoleucine, leucine, lysine, phenylalanine, threonine, tyrosine, valine). Ellipses represent 95% confidence ellipses for each nutrition group (autotrophy [symbiont] or heterotrophy [plankton-POM). Hawaii data are host (n=6), symbiont (n=6) and plankton (n=1); Palmyra data are host (n = 19), symbionts (n=11), plankton (n=9) and POM (n=8) (Fox et al. 2019).

ggsave("figures/LDA.EAA.norm.2source.pdf", height=5, width=5)

Compare the mean values of d13C-AA for samples of plankton and POM in Palmyra (Fox et al, 2019) with those of our study. This is Figure S5

# summary of means, pretty close
library(dplyr)
plank.meta<-Pacific.AA[(Pacific.AA$Fraction=="plank.HI" | 
                          Pacific.AA$Fraction=="plank.Pal" | 
                          Pacific.AA$Fraction=="POM.Pal"),]

plank.meta<-plank.meta[,c(-1:-2)] # remove extra columns

AA.means.mean<-plank.meta %>% 
  na.omit() %>%
    group_by(Fraction) %>%
    summarise_all("mean")


# melt column data to rows
md <- melt(plank.meta, id=("Fraction"))
colnames(md)<-c("Fraction", "AA", "d13C.AA")
md$Fraction<-droplevels(md$Fraction)
plank.metadf<-md

# drop levels to just Palmyra and Hawaii
plank.metadf$Fraction<-revalue(plank.metadf$Fraction, c("plank.Pal"="Plankton Palmyra", "POM.Pal"="POM Palmyra", "plank.HI" = "Plankton Hawaii"))

df.mean.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, mean, na.rm=TRUE)
df.SE.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, na.rm=TRUE, std.error)
df.n.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, length)
df.SE.pl[is.na(df.SE.pl)] <- 0
colnames(df.SE.pl)[3]="SE"
df.mean.pl<-cbind(df.mean.pl, df.SE.pl[3])


pd <- position_dodge(0.5) #offset for error bars

d13C.plank.POM.meta<-ggplot(df.mean.pl, aes(x=AA, y=d13C.AA, group=Fraction, shape=Fraction)) +
  geom_errorbar(aes(ymin=d13C.AA-SE, ymax=d13C.AA+SE, color=Fraction), size=.5, width=0, position=pd) +
  geom_point(aes(color=Fraction), size=2, position=pd) +
  ggtitle(expression(paste(delta^{13}, C[AA], " plankton"))) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Nonessential-AA", x=4, y=2.5, color="gray40") +
  annotate(geom="text", label="Essential-AA", x=10, y=2.5, color="gray40") +
  coord_cartesian(ylim=c(-35, 3)) + 
  xlab("Amino Acids") +
  scale_color_manual(values=c("lightgoldenrod4", "mediumorchid", "darkolivegreen3")) +
  scale_shape_manual(values=c(19,3,19))+
  ylab(expression(paste(delta^{13}, C[AA], " (\u2030, V-PDB)"))) +
  Fig.formatting
print(d13C.plank.POM.meta)
*Figure S5*. Comparison of δ13C values for non-essential and essential amino acids in a pooled plankton sample from Kāne‘ohe Bay, O‘ahu, Hawai‘i and plankton and POM from Palmyra (reported in (Fox et al. 2019)). Values are mean ± SE (n=6 - 9), except for the Hawai‘i plankton (n=1).

Figure S5. Comparison of δ13C values for non-essential and essential amino acids in a pooled plankton sample from Kāne‘ohe Bay, O‘ahu, Hawai‘i and plankton and POM from Palmyra (reported in (Fox et al. 2019)). Values are mean ± SE (n=6 - 9), except for the Hawai‘i plankton (n=1).

plot_grid(d13C.plank.POM.meta)
*Figure S5*. Comparison of δ13C values for non-essential and essential amino acids in a pooled plankton sample from Kāne‘ohe Bay, O‘ahu, Hawai‘i and plankton and POM from Palmyra (reported in (Fox et al. 2019)). Values are mean ± SE (n=6 - 9), except for the Hawai‘i plankton (n=1).

Figure S5. Comparison of δ13C values for non-essential and essential amino acids in a pooled plankton sample from Kāne‘ohe Bay, O‘ahu, Hawai‘i and plankton and POM from Palmyra (reported in (Fox et al. 2019)). Values are mean ± SE (n=6 - 9), except for the Hawai‘i plankton (n=1).

ggsave("figures/Fig S5. Pacific.plank.means.pdf", height=5, width=6, encod="MacRoman")


######

# drop levels to just Palmyra and Hawaii
plank.metadf$Fraction<-revalue(plank.metadf$Fraction, 
                          c("Plankton Palmyra"="Palmyra", "POM Palmyra"="Palmyra", "Plankton Hawaii"="Hawaii"))


df.mean.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, mean, na.rm=TRUE)
df.SE.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, na.rm=TRUE, std.error)
df.n.pl<-aggregate(d13C.AA~Fraction+AA, data=plank.metadf, length)
df.SE.pl[is.na(df.SE.pl)] <- 0
colnames(df.SE.pl)[3]="SE"
df.mean.pl<-cbind(df.mean.pl, df.SE.pl[3])


pd <- position_dodge(0.5) #offset for error bars

d13C.plank.meta<-ggplot(df.mean.pl, aes(x=AA, y=d13C.AA, group=Fraction)) +
  geom_errorbar(aes(ymin=d13C.AA-SE, ymax=d13C.AA+SE, color=Fraction), size=.5, width=0, position=pd) +
  geom_point(aes(color=Fraction), size=2, position=pd) +
  ggtitle(expression(paste(delta^{13}, C[AA], " plankton"))) +
  geom_vline(xintercept=7.5, linetype="solid", color = "gray") +
  annotate(geom="text", label="Nonessential-AA", x=4, y=2.5, color="gray40") +
  annotate(geom="text", label="Essential-AA", x=10, y=2.5, color="gray40") +
  coord_cartesian(ylim=c(-35, 3)) + 
  xlab("Amino Acids") +
  scale_color_manual(values=c("darkolivegreen4", "mediumorchid")) +
  ylab(expression(paste(delta^{13}, C[AA], " (\u2030, V-PDB)"))) +
  Fig.formatting
#print(d13C.plank.meta)